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