Skip to content

Instantly share code, notes, and snippets.

@ymyzk
Created June 10, 2016 04:50
Show Gist options
  • Save ymyzk/73342b92eb9c6f525f8fd0046234af4e to your computer and use it in GitHub Desktop.
Save ymyzk/73342b92eb9c6f525f8fd0046234af4e to your computer and use it in GitHub Desktop.
Performance comparison of C & Python
#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;
}
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