Created
August 30, 2014 17:07
-
-
Save kflu/2368e08c4fc3fc88666e to your computer and use it in GitHub Desktop.
Performance comparison: Node, Python, C#
This file contains hidden or 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
using System; | |
using System.Diagnostics; | |
namespace ConsoleApplication13 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int N = 10000000; | |
Stopwatch sw = new Stopwatch(); | |
sw.Start(); | |
for (int i = 0; i < N; i++) | |
{ | |
i += 1; | |
} | |
sw.Stop(); | |
Console.WriteLine("delta: " + sw.Elapsed.TotalMilliseconds * Math.Pow(10, 6) + " ns"); | |
// debug build: 20589300 ns | |
// release build: 3361400 ns | |
} | |
} | |
} |
This file contains hidden or 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 N = 10000000; | |
before = process.hrtime(); | |
for (var i = 0; i < N; i++) { | |
i += 1; | |
} | |
after = process.hrtime(); | |
delta = [0,0]; | |
delta[0] = after[0] - before[0]; | |
delta[1] = after[1] - before[1]; | |
console.log('time taken: ' + delta[0] + ' sec ' + delta[1] + ' ns '); | |
// 12014989ns |
This file contains hidden or 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
from time import clock | |
N = 10000000 | |
ii = range(N) | |
before = clock() | |
for i in ii: | |
i += 1 | |
after = clock() | |
print "time delta (ns)", (after - before) * (10**9) | |
# -OO: 1195017886.8 ns | |
# 1297932076.95 ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment