Toy routing speed measurement
This commit is contained in:
parent
622f14496e
commit
9c215008c7
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
all: t
|
all: t
|
||||||
|
|
||||||
t: *.c
|
t: *.c
|
||||||
$(CC) -Wall -O0 -o $@ -g *.c
|
$(CC) -Wall -Os -o $@ -g *.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f t
|
rm -f t
|
||||||
|
|
62
main.c
62
main.c
|
@ -2,6 +2,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "fasthash.h"
|
#include "fasthash.h"
|
||||||
#include "treetrie.h"
|
#include "treetrie.h"
|
||||||
|
@ -415,6 +417,66 @@ int main(int argc, char *argv[]) {
|
||||||
tt_drop(&a, C);
|
tt_drop(&a, C);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\n============================================================ C\n");
|
||||||
|
{
|
||||||
|
#define N_PATTERNS 10000
|
||||||
|
#define N_MESSAGES 10000000
|
||||||
|
tt_node_ptr_t r = TT_EMPTY;
|
||||||
|
struct timeval start_time, stop_time;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
gettimeofday(&start_time, NULL);
|
||||||
|
for (i = 0; i < N_PATTERNS; i++) {
|
||||||
|
tt_atom_t key = (i << 1) | 1;
|
||||||
|
tt_node_ptr_t d = tt_grab(&a, tt_dict_singleton(&a, key, TT_EMPTY));
|
||||||
|
tt_node_ptr_t p = tt_grab(&a, MAKE_PATH(&a, d, {TT_BOS, key, TT_WILD, TT_EOS}));
|
||||||
|
tt_replace(&a, &r, tt_trie_union_map(&a, r, p));
|
||||||
|
tt_drop(&a, d);
|
||||||
|
tt_drop(&a, p);
|
||||||
|
tt_drop(&a, r); /* because tt_trie_union_map returns grab'd */
|
||||||
|
}
|
||||||
|
gettimeofday(&stop_time, NULL);
|
||||||
|
{
|
||||||
|
double delta_ms = (stop_time.tv_sec - start_time.tv_sec) * 1000.0 +
|
||||||
|
(stop_time.tv_usec - start_time.tv_usec) / 1000.0;
|
||||||
|
printf("Construction time %g ms; that is, %g microsec per pattern, %.12g Hz\n",
|
||||||
|
delta_ms,
|
||||||
|
1000.0 * delta_ms / N_PATTERNS,
|
||||||
|
N_PATTERNS / (delta_ms / 1000.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("r node: %u/%u\n", tt_ptr_idx(r), tt_ptr_tag(r));
|
||||||
|
/* tt_arena_flush(&a); */
|
||||||
|
/* tt_dump_arena_dot_styled("r", r, &a, TT_STYLE_TEXT_LABELS /\* | TT_STYLE_HIDE_DETAILS *\/); */
|
||||||
|
|
||||||
|
gettimeofday(&start_time, NULL);
|
||||||
|
for (i = 0; i < N_MESSAGES; i++) {
|
||||||
|
tt_atom_t key = ((rand() % N_PATTERNS) << 1) | 1;
|
||||||
|
tt_node_ptr_t p = r;
|
||||||
|
p = tt_trie_step(&a, p, TT_BOS);
|
||||||
|
p = tt_trie_step(&a, p, key);
|
||||||
|
p = tt_trie_step(&a, p, key);
|
||||||
|
p = tt_trie_step(&a, p, TT_EOS);
|
||||||
|
assert(tt_ptr_tag(p) == TT_TAG_OK);
|
||||||
|
/* 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); */
|
||||||
|
}
|
||||||
|
gettimeofday(&stop_time, NULL);
|
||||||
|
{
|
||||||
|
double delta_ms = (stop_time.tv_sec - start_time.tv_sec) * 1000.0 +
|
||||||
|
(stop_time.tv_usec - start_time.tv_usec) / 1000.0;
|
||||||
|
printf("Routing time %g ms; that is, %g microsec per routed message, %.12g Hz\n",
|
||||||
|
delta_ms,
|
||||||
|
1000.0 * delta_ms / N_MESSAGES,
|
||||||
|
N_MESSAGES / (delta_ms / 1000.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
tt_drop(&a, r);
|
||||||
|
printf("\n");
|
||||||
|
#undef N_PATTERNS
|
||||||
|
#undef N_MESSAGES
|
||||||
|
}
|
||||||
|
|
||||||
tt_arena_flush(&a);
|
tt_arena_flush(&a);
|
||||||
tt_dump_arena_dot_styled("afterAll", TT_NO_PTR, &a, TT_STYLE_TEXT_LABELS); /* expect a_set and b_set here */
|
tt_dump_arena_dot_styled("afterAll", TT_NO_PTR, &a, TT_STYLE_TEXT_LABELS); /* expect a_set and b_set here */
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require prospect/route prospect/tset)
|
||||||
|
|
||||||
|
(define N-PATTERNS 10000)
|
||||||
|
(define N-MESSAGES 1000000)
|
||||||
|
|
||||||
|
(define (pat n) (pattern->matcher (datum-tset n) (list n ?)))
|
||||||
|
|
||||||
|
(define pats
|
||||||
|
(time
|
||||||
|
(for/fold [(p (matcher-empty))]
|
||||||
|
[(n (in-range N-PATTERNS))]
|
||||||
|
(matcher-union p (pat n)))))
|
||||||
|
|
||||||
|
;; (display (matcher->dot pats))
|
||||||
|
|
||||||
|
(collect-garbage)
|
||||||
|
(collect-garbage)
|
||||||
|
(collect-garbage)
|
||||||
|
|
||||||
|
(define-values (_result cpu-time delta-ms gc-time)
|
||||||
|
(time-apply
|
||||||
|
(lambda ()
|
||||||
|
(for [(j (in-range N-MESSAGES))]
|
||||||
|
(define i (random N-PATTERNS))
|
||||||
|
(matcher-match-value pats (list i i) #f)))
|
||||||
|
'()))
|
||||||
|
|
||||||
|
(printf "Delta ~a ms; that is, ~a microsec per routed message, ~a Hz\n"
|
||||||
|
delta-ms
|
||||||
|
(/ (* 1000.0 delta-ms) N-MESSAGES)
|
||||||
|
(/ N-MESSAGES (/ delta-ms 1000.0)))
|
Loading…
Reference in New Issue