[pypy-commit] extradoc extradoc: different results for different array sizes. cache effects?
hakanardo
noreply at buildbot.pypy.org
Thu Jun 9 07:45:55 CEST 2011
Author: Hakan Ardo <hakan at debian.org>
Branch: extradoc
Changeset: r3624:2c70b2e4e0bf
Date: 2011-06-09 07:46 +0200
http://bitbucket.org/pypy/extradoc/changeset/2c70b2e4e0bf/
Log: different results for different array sizes. cache effects?
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
@@ -6,12 +6,18 @@
$* sqrt/sqrt_double.c; /usr/bin/time -f %e ./a.out > /dev/null
$* sqrt/sqrt_long.c; /usr/bin/time -f %e ./a.out > /dev/null
$* sqrt/sqrt_fix16.c; /usr/bin/time -f %e ./a.out > /dev/null
- $* convolution/conv3.c; /usr/bin/time -f %e ./a.out > /dev/null
- $* convolution/conv5.c; /usr/bin/time -f %e ./a.out > /dev/null
+ $* convolution/conv3.c -lm; /usr/bin/time -f %e ./a.out 1 > /dev/null
+ $* convolution/conv5.c -lm; /usr/bin/time -f %e ./a.out 1 > /dev/null
+ $* convolution/conv3.c -lm; /usr/bin/time -f %e ./a.out 100 > /dev/null
+ $* 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
rm a.out
else
$* sqrt/time_sqrt.py float
$* sqrt/time_sqrt.py int
$* sqrt/time_sqrt.py Fix16
- $* convolution/time_conv.py
+ $* convolution/time_conv.py 1
+ $* convolution/time_conv.py 100
+ $* convolution/time_conv.py 1000
fi
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,22 +1,25 @@
#include <stdio.h>
+#include <math.h>
#define N 100000000
double a[N], b[N-2];
-//void conv(double *a, double *k, double *b) {
-void conv(double *__restrict__ a, double *__restrict__ k, double *__restrict__ b) {
+void conv(double *a, double *k, double *b, int n) {
+//void conv(double *__restrict__ a, double *__restrict__ k, double *__restrict__ b, int n) {
int i;
- for (i=0; i<N-2; i++) {
+ for (i=0; i<n-2; i++) {
b[i] = k[2]*a[i] + k[1]*a[i+1] + k[0]*a[i+2];
}
}
-int main() {
+int main(int ac, char **av) {
double k[3] = {-1, 0, 1};
- int i;
- for (i=0; i<N; i++) a[i] = 1;
- conv(a,k, b);
- printf("%f\n", b[N/2]);
- fprintf(stderr, "conv3: ");
- return 0;
+ int i;
+ for (i=0; i<N; i++) a[i] = 1;
+ int n = atoi(av[1]);
+ for (i=0; i<n; i++)
+ conv(a,k, b, N/n);
+ printf("%f\n", b[N/2]);
+ fprintf(stderr, "conv3(1e%d): ", ((int) log10(N/n)));
+ 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,22 +1,25 @@
#include <stdio.h>
+#include <math.h>
#define N 100000000
double a[N], b[N-4];
-//void conv(double *a, double *k, double *b) {
-void conv(double *__restrict__ a, double *__restrict__ k, double *__restrict__ b) {
+void conv(double *a, double *k, double *b, int n) {
+//void conv(double *__restrict__ a, double *__restrict__ k, double *__restrict__ b, int n) {
int i;
- for (i=0; i<N-4; i++) {
+ for (i=0; i<n-4; i++) {
b[i] = k[4]*a[i] + k[3]*a[i+1] + k[2]*a[i+2] + k[1]*a[i+3] + k[0]*a[i+4];
}
}
-int main() {
+int main(int ac, char **av) {
double k[5] = {1, 4, 6, 4, 1};
int i;
for (i=0; i<N; i++) a[i] = 1;
- conv(a,k, b);
+ int n = atoi(av[1]);
+ for (i=0; i<n; i++)
+ conv(a,k, b, N/n);
printf("%f\n", b[N/2]);
- fprintf(stderr, "conv5: ");
+ fprintf(stderr, "conv5(1e%d): ", ((int) log10(N/n)));
return 0;
}
diff --git a/talk/iwtc11/benchmarks/convolution/convolution.py b/talk/iwtc11/benchmarks/convolution/convolution.py
--- a/talk/iwtc11/benchmarks/convolution/convolution.py
+++ b/talk/iwtc11/benchmarks/convolution/convolution.py
@@ -1,15 +1,19 @@
from array import array
-def conv3(a, k):
+def conv3(a, k, n=1):
assert len(k)==3
b = array(a.typecode, [0]) * (len(a) - 2)
- for i in xrange(len(b)):
- b[i] = k[2]*a[i] + k[1]*a[i+1] + k[0]*a[i+2]
+ while n:
+ n -= 1
+ for i in xrange(len(b)):
+ b[i] = k[2]*a[i] + k[1]*a[i+1] + k[0]*a[i+2]
return b
-def conv5(a, k):
+def conv5(a, k, n=1):
assert len(k)==5
b = array(a.typecode, [0]) * (len(a) - 4)
- for i in xrange(len(b)):
- b[i] = k[4]*a[i] + k[3]*a[i+1] + k[2]*a[i+2] + k[1]*a[i+3] + k[0]*a[i+4]
+ while n:
+ n -= 1
+ for i in xrange(len(b)):
+ b[i] = k[4]*a[i] + k[3]*a[i+1] + k[2]*a[i+2] + k[1]*a[i+3] + k[0]*a[i+4]
return b
diff --git a/talk/iwtc11/benchmarks/convolution/time_conv.py b/talk/iwtc11/benchmarks/convolution/time_conv.py
--- a/talk/iwtc11/benchmarks/convolution/time_conv.py
+++ b/talk/iwtc11/benchmarks/convolution/time_conv.py
@@ -1,16 +1,19 @@
from convolution import conv3, conv5
from array import array
import sys, time
+from math import log10
+
+n = int(sys.argv[1])
a = time.time()
-conv3(array('d', [1]) * 100000000,
- array('d', [-1, 0, 1]))
+conv3(array('d', [1]) * (100000000/n),
+ array('d', [-1, 0, 1]), n)
b = time.time()
-print 'conv3: ', b - a
+print 'conv3(1e%d): ' % log10(100000000/n), b - a
a = time.time()
-conv5(array('d', [1]) * 100000000,
- array('d', [1, 4, 6, 4, 1]))
+conv5(array('d', [1]) * (100000000/n),
+ array('d', [1, 4, 6, 4, 1]), n)
b = time.time()
-print 'conv5: ', b - a
+print 'conv5(1e%d): ' % log10(100000000/n), b - a
More information about the pypy-commit
mailing list