Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F5896667
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
cem
Nov 20 2019, 8:40 PM
2019-11-20 20:40:48 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
#define _BSD_VISIBILE
#include <sys/param.h>
#include <sys/time.h>
#include <err.h>
#include <assert.h>
#include <stdio.h>
#include <time.h>
static inline int64_t
mynow(void)
{
int x;
struct timespec tp;
x = clock_gettime(CLOCK_VIRTUAL, &tp);
assert(x == 0);
return (tstosbt(tp));
}
int
main(int argc, char **argv)
{
size_t iterations = 1, i;
int64_t a, b, t;
size_t sz;
unsigned sec, usec;
for (t = 0; t < mstosbt(100); iterations *= 2) {
a = mynow();
for (i = 0; i < iterations; i++) {
int retry = 10;
unsigned long rndval;
__asm __volatile(
"1:\n\t"
"rdrand %1\n\t"
"jc 2f\n\t"
"dec %0\n\t"
"jne 1b\n\t"
"2:"
: "+r" (retry), "=r" (rndval) : : "cc");
if (retry == 0)
errx(1, "failed 10 times");
}
b = mynow();
t = b - a;
}
sz = sizeof(unsigned long);
sec = t >> 32;
usec = sbttous(t & 0xffffffff);
printf("%zu iterations of %zu bytes each took %u.%06u seconds.ms, or\n",
iterations, sz, sec, usec);
double x = (double)sz * iterations / (sec + (((double)usec) / 1000000));
printf("%.3f B/s %.3f kB/s %.3f MiB/s\n", x, x/1024, x/1024/1024);
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2436607
Default Alt Text
raw.txt (1 KB)
Attached To
Mode
P336 crappy rdrand microbench
Attached
Detach File
Event Timeline
Log In to Comment