Open timotheecour opened 3 years ago
weird:
and that's true even if we change in generated code var a_704643094 = new Int32Array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ...]);
to var a_704643094 = new Int32Array(10);
when defined case2b:
#[
]#
import times, macros
macro getArray(): untyped =
result = newTree(nnkBracket)
let m = 10
for i in 0..<m:
result.add newLit 3
proc main()=
let n = 10000000
let t = now()
var x = 0
let a = getArray()
for i in 0..<n:
for j in a:
x += a[j]
let t2 = now()
echo (t2 - t, x)
for i in 0..<3:
echo i
main()
@xflywind is this benchmark flawed / representative?
benchmark refs https://github.com/nim-lang/Nim/pull/16850#discussion_r566711862
Example
before PR https://github.com/nim-lang/Nim/pull/16850
nim r -b:js -d:danger main
0 (144 milliseconds, 300000000) 1 (148 milliseconds, 300000000) 2 (174 milliseconds, 300000000)
after PR
0 (1 second and 469 milliseconds, 300000000) 1 (1 second and 441 milliseconds, 300000000) 2 (1 second and 424 milliseconds, 300000000)
links