#include #include typedef struct Movtab Movtab; typedef void* (*Movfn)(void*, void*, ulong); u32int runtimecpuid_edx = 0x4000000; extern void* runtimememmove(void*, void*, ulong); struct Movtab { Movfn f; char *name; }; uvlong hz; int sztab[] = {1, 2, 4, 8, 16, 32, 64, 128, 512, 1024, 4096, 128*1024, }; uchar buf0[128*1024]; uchar buf1[128*1024]; Movtab movtab[] = {memmove, "memmove", runtimememmove, "rt·memmove", }; //Movfn movtab[] = {memmove, runtimememmove}; uvlong gethz(void) { char buf[1024], *f[5]; int n, fd; fd = open("/dev/time", OREAD); if(fd == -1) sysfatal("%s: open /dev/time: %r", argv0); n = pread(fd, buf, sizeof buf-1, 0); if(n <= 0) sysfatal("%s: read /dev/time: %r", argv0); buf[n] = 0; n = tokenize(buf, f, nelem(f)); if(n < 4) sysfatal("%s: /dev/time: unexpected fmt", argv0); return strtoull(f[3], 0, 0); } void inner(Movfn f, ulong sz) { int i; for(i = 0; i < 1024; i++) f(buf1, buf0, sz); } void main(int argc, char **argv) { int i, j; uvlong t[2], c[nelem(movtab)][nelem(sztab)]; // double dhz; Movfn f; ARGBEGIN{ }ARGEND hz = gethz(); // dhz = hz; for(i = 0; i < 2; i++){ print("%s\n", movtab[i].name); f = movtab[i].f; for(j = 0; j < nelem(sztab); j++){ cycles(t + 0); inner(f, sztab[j]); cycles(t + 1); c[i][j] = t[1] - t[0]; print("%d %g cycles/op\n", sztab[j], c[i][j]/1024.); sleep(0); } print("\n"); } exits(""); }