timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

js: benchmark for typed arrays, refs https://github.com/nim-lang/Nim/pull/16850 #567

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

@xflywind is this benchmark flawed / representative?

benchmark refs https://github.com/nim-lang/Nim/pull/16850#discussion_r566711862

Example

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
  for i in 0..<n:
    let a = getArray()
    for j in a: # same conclusions w: for j in 0..<a.len:
      x += a[j]
  let t2 = now()
  echo (t2 - t, x)

for i in 0..<3:
  echo i
  main()

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

timotheecour commented 3 years ago

weird: