Last active
August 24, 2019 18:15
-
-
Save peterfoxflick/ab6db2fa436eb5755c748cbb4da8c813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
%x(rm output.csv) | |
file = File.open('output.csv', 'a') | |
file.puts("N,DoWhile,ForEach,ForOf,ForLoop,While") | |
file.close | |
10000.times{ |i| | |
file = File.open('output.csv', 'a') | |
time = Benchmark.measure { | |
%x(node dowhile.js) | |
} | |
output = (i + 1).to_s + "," + time.real.to_s | |
time = Benchmark.measure { | |
%x(node foreach.js) | |
} | |
output = output + "," + time.real.to_s | |
time = Benchmark.measure { | |
%x(node forof.js) | |
} | |
output = output + "," + time.real.to_s | |
time = Benchmark.measure { | |
%x(node forloop.js) | |
} | |
output = output + "," + time.real.to_s | |
time = Benchmark.measure { | |
%x(node while.js) | |
} | |
output = output + "," + time.real.to_s | |
file.puts(output) | |
file.close | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new Array(1000) | |
for(var i = 0; i < arr.length; i++){ | |
arr[i] = i | |
} | |
var sum = 0 | |
var i = 0 | |
do { | |
sum += arr[i] * 2 | |
i++ | |
} while ( i < arr.length ) | |
console.log("SUM: " + sum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new Array(1000) | |
for(var i = 0; i < arr.length; i++){ | |
arr[i] = i | |
} | |
var sum = 0 | |
arr.forEach(i => { | |
sum += i * 2 | |
}) | |
console.log("SUM: " + sum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new Array(1000) | |
for(var i = 0; i < arr.length; i++){ | |
arr[i] = i | |
} | |
var sum = 0 | |
for(var i = 0; i < arr.length; i++){ | |
sum += arr[i] * 2 | |
} | |
console.log("SUM: " + sum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new Array(1000) | |
for(var i = 0; i < arr.length; i++){ | |
arr[i] = i | |
} | |
var sum = 0 | |
for(var i of arr){ | |
sum += i * 2 | |
} | |
console.log("SUM: " + sum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new Array(1000) | |
for(var i = 0; i < arr.length; i++){ | |
arr[i] = i | |
} | |
var sum = 0 | |
var i = 0 | |
while (i < arr.length) { | |
sum += arr[i] * 2 | |
i++ | |
} | |
console.log("SUM: " + sum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment