Skip to content

Instantly share code, notes, and snippets.

@Zig1375

Zig1375/bm.js Secret

Created July 2, 2021 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zig1375/a972207158edb523ce04219d84885469 to your computer and use it in GitHub Desktop.
Save Zig1375/a972207158edb523ce04219d84885469 to your computer and use it in GitHub Desktop.
Benchmark for NodeJS and Ruby
'use strict';
class MyClass {
constructor(aa, bb) {
this.a = aa;
this.b = bb;
}
sum() {
return this.a + this.b;
}
}
const cnt = 10000000
const list = [];
for(let i = 0; i < cnt; i++) {
list.push(new MyClass(i, i - 10));
}
let res = 0
list.forEach((it) => {
res += it.sum();
});
console.log(res)
class MyClass
def initialize(aa, bb)
@a = aa
@b = bb
end
def sum
@a + @b
end
end
cnt = 10000000
list = []
cnt.times.each do|i|
list << MyClass.new(i, i - 10)
end
res = 0
list.each do|it|
res += it.sum
end
puts res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment