[pypy-commit] extradoc extradoc: Add array benchmark

fijal noreply at buildbot.pypy.org
Mon Jun 13 11:15:49 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: extradoc
Changeset: r3657:4c8e1b00e547
Date: 2011-06-13 11:17 +0200
http://bitbucket.org/pypy/extradoc/changeset/4c8e1b00e547/

Log:	Add array benchmark

diff --git a/talk/iwtc11/benchmarks/numpy/array.c b/talk/iwtc11/benchmarks/numpy/array.c
new file mode 100644
--- /dev/null
+++ b/talk/iwtc11/benchmarks/numpy/array.c
@@ -0,0 +1,36 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+double *create_array(int size)
+{
+  int i;
+  double *a = (double*)malloc(size * sizeof(double));
+  for (i = 0; i < size; ++i) {
+    a[i] = (double)(i % 10);
+  }
+  return a;
+}
+
+#define MAX 5
+#define SIZE 10000000
+#define ITERATIONS 10
+
+int main()
+{
+  double *a[MAX];
+  double *res;
+  int i, k;
+
+  for (i = 0; i < MAX; ++i) {
+    a[i] = create_array(SIZE);
+  }
+  res = create_array(SIZE);
+  // actual loop
+  for (k = 0; k < ITERATIONS; ++k) {
+    for (i = 0; i < SIZE; ++i) {
+      res[i] = a[0][i] + a[1][i] + a[2][i] + a[3][i] + a[4][i];
+    }
+    printf("%f\n", res[125]); // to kill the optimizer
+  }
+}


More information about the pypy-commit mailing list