Commits

Maciej Fijalkowski  committed a600d6a

benchmarks

  • Participants
  • Parent commits 91f4fdc

Comments (0)

Files changed (2)

File bench/numeric/arr.c

+
+#include <stdio.h>
+#include <stdlib.h>
+
+double sum(int size, double *res)
+{
+  int i;
+  double s;
+  for (i = 0; i < size; ++i)
+    s += res[i];
+  return s;
+}
+
+#define FILENAME "/tmp/a.data"
+
+void init_file(int size, double *arr)
+{
+  int i;
+  int count = 0;
+  FILE* f = fopen(FILENAME, "r");
+  while (count < size) {
+    count += fread(arr, 1, size - count, f);
+  }
+  fclose(f);
+}
+
+void init(int size, double *arr, double what)
+{
+  int i;
+  int count;
+  for (i = 0; i < size; ++i)
+    arr[i] = what;
+}
+
+void add(int size, double *a, double *b, double *res)
+{
+  int i;
+  for (i = 0; i < size; i++)
+    res[i] = res[i] + a[i] + b[i];
+}
+
+double* new_arr(int size, double what)
+{
+  double *a;
+  a = (double*)malloc(sizeof(double) * size);
+  if (what == -1) {
+    init_file(size, a);
+  } else {
+    init(size, a, what);
+  }
+  return a;
+}
+
+int main(int argc, char **argv)
+{
+  double *a, *b, *res, *c, *d, *e, *tmp1, *tmp2, *tmp3;
+  int size = atoi(argv[1]);
+  int i;
+  double what;
+  double s;
+  int n = atoi(argv[2]);
+  a = new_arr(size, -1);
+  b = new_arr(size, -1);
+  c = new_arr(size, -1);
+  d = new_arr(size, -1);
+  e = new_arr(size, -1);
+  tmp1 = new_arr(size, 0);
+  tmp2 = new_arr(size, 0);
+  tmp3 = new_arr(size, 0);
+  res = new_arr(size, 0);
+  for (i = 0; i < n; ++i) {
+    init(size, tmp1, 0);
+    add(size, a, b, tmp1);
+    init(size, tmp2, 0);
+    init(size, tmp3, 0);
+    add(size, c, d, tmp2);
+    add(size, tmp1, e, tmp3);
+    add(size, tmp3, tmp2, res);
+  }
+  s = sum(size, res);
+  printf("%f\n", s);
+}

File bench/numeric/arr.py

+
+import sys, struct
+
+try:
+    from numpypy import zeros, fromstring
+    from _numpypy.pypy import remove_invalidates
+except:
+    from numpy import zeros
+    remove_invalidates = lambda arg: None
+
+def hook(jitdriver_name, loop_type, greenkey, operations):
+    return [i for i in operations if 'assert' not in str(i)]
+
+try:
+    import pypyjit
+#    pypyjit.set_optimize_hook(hook)
+except:
+    pass
+
+size = int(sys.argv[1])
+
+def init():
+    with open("/tmp/a.data") as f:
+        return fromstring(f.read(), dtype=float)
+
+count = int(sys.argv[2])
+a, b, c, d, e = [init() for i in range(5)]
+r = zeros(size)
+for i in range(count):
+    r[:] = (a + b) + ((c + d) + e)
+