[TOC] # 考察:KSP・処理速度を向上させる(CPU負荷を下げる) ###### tags: `ksp` `kontakt` 基本は一般的なプログラミング言語・スクリプト言語のTipsが適用できる ## 分岐、サブルーチンコール KSPで言う - if - select - while - call - ビルトインコマンド呼び出し である。 ## 実測環境 - Mac mini Late 2012 - macOS: 10.12 - Intel Core i7 - KONTAKT: Player 5.7.0 ## inc/dec コマンド 一見コマンドコールのコストがつきそうだが、実測すると高速である。 ~~~ $i := $i + 1 ~~~ やるぐらいなら inc の方が速い。 ## call コマンド 500 microseconds / call 関数内で更に call コマンド読んでいる場合はその分 * 500 microseconds ## 簡単に高速化が見込める要素 call コマンドを全てインライン展開する オブファスケーターで対応済み。(BETA2で) 処理自体は何のことはなく、ASTがcall実行部に到達した際、単純に呼び出し先の関数ノードを出力している。 以下は、on note イベント時に負荷テストを行ったコードである。 ### Before 結果:4500 microseconds前後 ~~~ on init declare $i end on function functionName2 message( "Hello" ) end function function functionName call functionName2 end function on note $i := 0 reset_ksp_timer while( $i < 10000 ) call functionName call functionName call functionName call functionName inc( $i ) end while message( $KSP_TIMER ) end on ~~~ ### After 結果:2000 microseconds前後 たったこれだけのコードでも半分である。とは言え、単位はマイクロ秒である。 塵も積もれば何とやら(?) ~~~ on init declare $_74b8 end on on note $_74b8:=0 reset_ksp_timer while($_74b8<10000) message("Hello") message("Hello") message("Hello") message("Hello") inc($_74b8) end while message($KSP_TIMER) end on ~~~
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up