Created
November 25, 2015 21:44
-
-
Save tobgu/41bed2bc96cbfaa12e76 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
/* test.c */ | |
#include <stdio.h> | |
#define LEN 200000000 | |
void main() { | |
static int arr[LEN]; | |
int i = 0; | |
int result = 0; | |
for(i = 0; i < LEN; i++) { | |
arr[i] = 1; | |
} | |
for(i = 0; i < LEN; i++) { | |
result += arr[i]; | |
} | |
printf("%i\n", result); | |
} | |
/* test.go */ | |
package main | |
import "fmt" | |
func main() { | |
const length = 200000000 | |
var arr [length]int | |
for i := 0; i < length; i++ { | |
arr[i] = 1 | |
} | |
result := 0 | |
for i := 0; i < length; i++ { | |
result += arr[i] | |
} | |
fmt.Println(result) | |
} | |
# test.py | |
print sum(200000000 * [1]) | |
=== Results === | |
$ gcc test.c | |
$ time ./a.out | |
200000000 | |
real 0m1.187s | |
user 0m1.034s | |
sys 0m0.109s | |
$ time go run test.go | |
200000000 | |
real 0m1.086s | |
user 0m0.846s | |
sys 0m0.394s | |
$ time python test.py | |
200000000 | |
real 0m2.838s | |
user 0m2.483s | |
sys 0m0.290s | |
$ time pypy test.py | |
200000000 | |
real 0m1.022s | |
user 0m0.736s | |
sys 0m0.261s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment