1. Maciej Fijalkowski
  2. hack2

Commits

Maciej Fijalkowski  committed fedafc5

implement scenarios

  • Participants
  • Parent commits a8852fe
  • Branches default

Comments (0)

Files changed (3)

File bench/numeric/arr.c

View file
+
+
+/* 3 args - array size, number of iterations, number of scenario
+   Scenarios:
+   0 - a + b
+   1 - a + (b + c)
+   2 - (a + b) + ((c + d) + e)
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
   double what;
   double s;
   int n = atoi(argv[2]);
+  int bench = atoi(argv[3]);
   a = new_arr(size, -1);
   b = new_arr(size, -1);
   c = new_arr(size, -1);
   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);
+    if (bench == 0) {
+      add(size, a, b, res);
+    } else if (bench == 1) {
+      init(size, tmp1, 0);
+      add(size, b, c, tmp1);
+      add(size, a, tmp1, res);
+    } else if (bench == 2) {
+      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

View file
 
 count = int(sys.argv[2])
 a, b, c, d, e = [init() for i in range(5)]
+scenario = int(sys.argv[3])
 r = zeros(size)
 for i in range(count):
-    r[:] = (a + b) + ((c + d) + e)
+    if scenario == 0:
+        r[:] = a + b
+    elif scenario == 1:
+        r[:] = a + (b + c)
+    elif scenario == 2:
+        r[:] = (a + b) + ((c + d) + e)
 print r.sum()

File bench/numeric/arrloop.c

View file
+
+/* 3 args - array size, number of iterations, number of scenario
+   Scenarios:
+   0 - a + b
+   1 - a + (b + c)
+   2 - (a + b) + ((c + d) + e)
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
 {
   double *a, *b, *res, *c, *d, *e, *tmp1, *tmp2, *tmp3;
   int size = atoi(argv[1]);
+  int bench = atoi(argv[3]);
   int i, k;
   double what;
   double s;
   e = new_arr(size, -1);
   res = new_arr(size, 0);
   for (i = 0; i < n; ++i) {
-    for (k = 0; k < size; k++) {
-      res[k] = (a[k] + b[k]) + ((c[k] + d[k]) + e[k]);
+    if (bench == 0) {
+      for (k = 0; k < size; k++) {
+        res[k] = (a[k] + b[k]);
+      }
+    } else if (bench == 1) {
+      for (k = 0; k < size; k++) {
+        res[k] = (a[k] + b[k]) + c[k];
+      }
+    } else if (bench == 2) {
+      for (k = 0; k < size; k++) {
+        res[k] = (a[k] + b[k]) + ((c[k] + d[k]) + e[k]);
+      }
     }
   }
   s = sum(size, res);