/* simplewritespeed.c - simplistic memory writespeed test * Written by Harry Sintonen . Public Domain. * * Compile: gcc -O2 simplewritespeed.c -o simplewritespeed * * If you run this under multitasking environment, please make * sure there are no busy background processes eating CPU time. * Even with idle systems, results are probably slightly slower * than possible under optimum conditions. * * WARNING: You must fix BASE and SIZE variables below before * compiling. The memory located at BASE will be trashed by * this test. I told you this was simple. :) * */ #include #include #include #define MEG (1024 * 1024) /* NOTE: These MUST be fixed! */ #define BASE 0xe8000000 /* memory base */ #define SIZE 16 * MEG /* size of the memory area to write */ #define ROUNDS 32 /* number of loops */ /* Adjust for your target CPU. These are ok for 32bit CPUs */ typedef unsigned int u32t; typedef unsigned long long u64t; typedef double f64t; int main(void) { struct timeval beg, end; f64t *ptr; u32t totalsize; u64t totaltime; u32t speed; int i; gettimeofday(&beg, NULL); for (i = 0; i < ROUNDS; i++) { u32t lcnt = SIZE / (sizeof(f64t) * 4); ptr = (f64t *) BASE; do { *ptr++ = 123456.789; *ptr++ = 123456.789; *ptr++ = 123456.789; *ptr++ = 123456.789; } while (--lcnt); } gettimeofday(&end, NULL); totalsize = SIZE * ROUNDS / MEG; totaltime = ((u64t) end.tv_sec * 1000000 + end.tv_usec) - ((u64t) beg.tv_sec * 1000000 + beg.tv_usec); speed = (u64t) totalsize * 100000000 / totaltime; printf("%u MB written in %u.%06u seconds, %u.%02u MB/s\n", totalsize, (u32t) (totaltime / 1000000), (u32t) (totaltime % 1000000), speed / 100, speed % 100); return 0; }