This commit is contained in:
Tony Garnock-Jones 2015-08-03 11:14:35 -04:00
parent 4afeb7f515
commit 2408ebe255
1 changed files with 14 additions and 0 deletions

14
main.c
View File

@ -108,6 +108,14 @@ int main1(int argc, char *argv[]) {
return EXIT_SUCCESS;
}
/* http://wiki.osdev.org/Inline_Assembly/Examples#RDTSC */
static inline uint64_t rdtsc(void)
{
uint64_t ret;
asm volatile ( "rdtsc" : "=A"(ret) );
return ret;
}
static tt_node_ptr_t make_path(tt_arena_t *a, tt_node_ptr_t ok_dict, int n, tt_atom_t const *atoms)
{
int i;
@ -423,6 +431,7 @@ int main(int argc, char *argv[]) {
#define N_MESSAGES 10000000
tt_node_ptr_t r = TT_EMPTY;
struct timeval start_time, stop_time;
uint64_t start_cycles, stop_cycles;
int i;
gettimeofday(&start_time, NULL);
@ -450,6 +459,7 @@ int main(int argc, char *argv[]) {
/* tt_dump_arena_dot_styled("r", r, &a, TT_STYLE_TEXT_LABELS /\* | TT_STYLE_HIDE_DETAILS *\/); */
gettimeofday(&start_time, NULL);
start_cycles = rdtsc();
for (i = 0; i < N_MESSAGES; i++) {
tt_atom_t key = ((rand() % N_PATTERNS) << 1) | 1;
tt_node_ptr_t p = r;
@ -461,6 +471,7 @@ int main(int argc, char *argv[]) {
/* printf("\nstepped: key %d, %u/%u\n", key, tt_ptr_idx(p), tt_ptr_tag(p)); */
/* tt_dump_arena_dot_styled("result", p, &a, TT_STYLE_TEXT_LABELS); */
}
stop_cycles = rdtsc();
gettimeofday(&stop_time, NULL);
{
double delta_ms = (stop_time.tv_sec - start_time.tv_sec) * 1000.0 +
@ -469,6 +480,9 @@ int main(int argc, char *argv[]) {
delta_ms,
1000.0 * delta_ms / N_MESSAGES,
N_MESSAGES / (delta_ms / 1000.0));
printf("%lld cycles elapsed; %g cycles per routed message\n",
((long long int) stop_cycles - (long long int) start_cycles),
(double) (stop_cycles - start_cycles) / N_MESSAGES);
}
tt_drop(&a, r);