Author: Hakan Ardo <ha...@debian.org> Branch: extradoc Changeset: r3631:76d328dab4cb Date: 2011-06-09 21:43 +0200 http://bitbucket.org/pypy/extradoc/changeset/76d328dab4cb/
Log: hg merge diff --git a/talk/iwtc11/benchmarks/benchmark.sh b/talk/iwtc11/benchmarks/benchmark.sh --- a/talk/iwtc11/benchmarks/benchmark.sh +++ b/talk/iwtc11/benchmarks/benchmark.sh @@ -12,6 +12,8 @@ $* convolution/conv5.c -lm; /usr/bin/time -f %e ./a.out 100 > /dev/null $* convolution/conv3.c -lm; /usr/bin/time -f %e ./a.out 1000 > /dev/null $* convolution/conv5.c -lm; /usr/bin/time -f %e ./a.out 1000 > /dev/null + $* convolution/conv3x3.cc -lstdc++; /usr/bin/time -f %e ./a.out 1000000 3 > /dev/null + $* convolution/conv3x3.cc -lstdc++; /usr/bin/time -f %e ./a.out 1000 1000 > /dev/null rm a.out else $* sqrt/time_sqrt.py float diff --git a/talk/iwtc11/benchmarks/convolution/conv3.c b/talk/iwtc11/benchmarks/convolution/conv3.c --- a/talk/iwtc11/benchmarks/convolution/conv3.c +++ b/talk/iwtc11/benchmarks/convolution/conv3.c @@ -1,8 +1,9 @@ #include <stdio.h> #include <math.h> +#include <stdlib.h> #define N 100000000 -double a[N], b[N-2]; +double *a, *b; void conv(double *a, double *k, double *b, int n) { //void conv(double *__restrict__ a, double *__restrict__ k, double *__restrict__ b, int n) { @@ -14,6 +15,8 @@ int main(int ac, char **av) { double k[3] = {-1, 0, 1}; + a = malloc(N*sizeof(double)); + b = malloc(N*sizeof(double)); int i; for (i=0; i<N; i++) a[i] = 1; int n = atoi(av[1]); diff --git a/talk/iwtc11/benchmarks/convolution/conv3x3.cc b/talk/iwtc11/benchmarks/convolution/conv3x3.cc new file mode 100644 --- /dev/null +++ b/talk/iwtc11/benchmarks/convolution/conv3x3.cc @@ -0,0 +1,46 @@ +// A safe array example. +#include <stdio.h> +#include <stdlib.h> + +class Array2D { + double *data; +public: + int width, height; + Array2D(int w, int h) { + width = w; + height = h; + data = (double *) malloc(w*h*sizeof(double)); + } + double &operator()(int x, int y) { + if (x >= 0 && x < width && y >= 0 && y < height) { + return data[y*width + x]; + } + printf("IndexError\n"); + exit(1); + } +}; + +void conv3x3(Array2D &a, Array2D &k, Array2D &b) { + int x, y; + for (y=1; y<a.height-1; y++) { + for (x=1; x<a.width-1; x++) { + b(x, y) = k(2,2)*a(x-1, y-1) + k(1,2)*a(x, y-1) + k(0,2)*a(x+1, y-1) + + k(2,1)*a(x-1, y) + k(1,1)*a(x, y) + k(0,1)*a(x+1, y) + + k(2,0)*a(x-1, y+1) + k(1,0)*a(x, y+1) + k(0,0)*a(x+1, y+1); + + } + } +} + +int main(int ac, char **av) { + int w = atoi(av[1]), h = atoi(av[2]); + int i; + + for (i=0; i<10; i++) { + Array2D a(w, h), b(w, h), k(3, 3); + conv3x3(a, k, b); + printf("%f\n", b(1,1)); + } + fprintf(stderr, "conv3x3(%d): ", h); + return 0; +} diff --git a/talk/iwtc11/benchmarks/convolution/conv5.c b/talk/iwtc11/benchmarks/convolution/conv5.c --- a/talk/iwtc11/benchmarks/convolution/conv5.c +++ b/talk/iwtc11/benchmarks/convolution/conv5.c @@ -1,8 +1,9 @@ #include <stdio.h> #include <math.h> +#include <stdlib.h> #define N 100000000 -double a[N], b[N-4]; +double *a, *b; void conv(double *a, double *k, double *b, int n) { //void conv(double *__restrict__ a, double *__restrict__ k, double *__restrict__ b, int n) { @@ -14,6 +15,8 @@ int main(int ac, char **av) { double k[5] = {1, 4, 6, 4, 1}; + a = malloc(N*sizeof(double)); + b = malloc(N*sizeof(double)); int i; for (i=0; i<N; i++) a[i] = 1; int n = atoi(av[1]); _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit