Files
hakorune/apps/ny-array-bench/main.hako

99 lines
2.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ny-array-bench - ArrayBox性能ベンチマーク
// 目的: ArrayBox map/reduce、簡易可視化VM/JIT整合優先の最小版
// 出力: JSON形式のベンチマーク結果CI集計用
// 計測・集計は無効化VM/JITで同一挙動を優先
static box Main {
init { console }
main(args) {
me.console = new ConsoleBox()
// ベンチマーク設定ArrayBoxで明示作成
local sizes = new ArrayBox()
sizes.push(1000)
sizes.push(10000)
sizes.push(100000)
me.console.log("=== Nyash Array Benchmark ===")
me.console.log("Backend: " + me.getBackend())
me.console.log("")
// 各サイズでベンチマーク実行
local idx = 0
local n = sizes.length()
loop(idx < n) {
local size = sizes.get(idx)
me.console.log("Testing size: " + size)
me.benchArrayOps(size)
idx = idx + 1
}
// JSON結果出力固定の空オブジェクト
local result = "{}"
print(result)
return 0
}
getBackend() {
// 実行環境の判定(簡易版: VM固定
return "vm"
}
benchArrayOps(size) {
// VM/JIT 通過用の最小ダミー
}
// map実装×クロージャ → ○固定処理: 2倍
mapArrayDouble(array) {
local result = new ArrayBox()
local length = array.length()
local i = 0
loop(i < length) {
local value = array.get(i)
result.push(value * 2)
i = i + 1
}
return result
}
// reduce実装総和
reduceArraySum(array) {
local acc = 0
local length = array.length()
local i = 0
loop(i < length) {
acc = acc + array.get(i)
i = i + 1
}
return acc
}
// find実装等値
findInArrayEq(array, target) {
local length = array.length()
local i = 0
loop(i < length) {
local value = array.get(i)
if value == target {
return value
}
i = i + 1
}
return null
}
calculateRelativePerformance() {
// VMのみ記録簡易
StatsBox.recordRelative("vm", 1.0)
}
}