oops. botched fix of harmess warning.
corrected source attached.
just for a giggle, i ran this test on a few handy machines to get a feel
for relative speed of a single core. since this test is small enough to
fit in the tiniest cache, i would think that memory speed or any other
external factor would be unimportant:
open rd/marvell kirkwood 471.97u 0.00s 472.25r
Intel(R) Atom(TM) CPU 330 @ 1.60GHz 48.47u 0.00s 48.48r
Intel(R) Pentium(R) 4 CPU 3.00GHz 40.72u 0.00s 40.76r
AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ 30.62u 0.00s 30.64r
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ 23.18u 0.00s 23.19r
Intel(R) Xeon(R) CPU 5120 @ 1.86GHz 23.16u 0.00s 23.08r
Intel(R) Xeon(R) CPU E5540 @ 2.53GHz 17.26u 0.00s 17.26r
Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz 16.86u 0.00s 16.86r
Intel(R) Xeon(R) CPU E5630 @ 2.53GHz 10.46u 0.00s 10.50r
perhaps the arm's vlong arithmitic isn't as well optimized as x86. the
atom also is conspicuously slow, but unfortunately with no obvious
excuses.
- erik
#include <u.h>
#include <libc.h>
#include <thread.h>
#define Scale (100000000000ull)
/*
* waste time
*/
vlong
πjj(uint j)
{
vlong v;
v = 4*Scale / (2*j + 1);
if(j&1)
return -v;
return v;
}
vlong
π(void)
{
uint i;
vlong v;
v = 0;
for(i = 0; i < 500000000; i++)
v += πjj(i);
return v;
}
void
p(void *v)
{
int i;
i = (int)v;
print("%d: %lld\n", i, π());
threadexits("");
}
void
usage(void)
{
fprint(2, "usage: burncycles nthread\n");
threadexits("usage");
}
void
threadmain(int argc, char **argv)
{
int n, i;
ARGBEGIN{
default:
usage();
}ARGEND
n = 0;
if(argc == 0)
n = 1;
else if(argc != 1 || (n = atoi(argv[0])) <= 0)
usage();
for(i = 0; i < n-1; i++)
proccreate(p, (void*)i, 4096);
p((void*)i);
}