Created
June 10, 2016 04:50
-
-
Save ymyzk/73342b92eb9c6f525f8fd0046234af4e to your computer and use it in GitHub Desktop.
Performance comparison of C & Python
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
#include <stdio.h> | |
#define N 1024 | |
int main(void) { | |
int a[N][N]; | |
int b[N][N]; | |
int c[N][N]; | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
a[i][j] = i * j; | |
b[i][j] = i + j; | |
} | |
} | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
c[i][j] = 0; | |
for (int k = 0; k < N; k++) { | |
c[i][j] += a[i][k] + b[k][j]; | |
} | |
} | |
} | |
return 0; | |
} |
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
N = 1024 | |
a = [[i * j for i in range(N)] for j in range(N)] | |
b = [[i + j for i in range(N)] for j in range(N)] | |
c = [[0 for _ in range(N)] for _ in range(N)] | |
for i in range(N): | |
for j in range(N): | |
for k in range(N): | |
c[i][j] += a[i][k] + b[k][j] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment