Skip to content
Newer
Older
100644 147 lines (129 sloc) 2.26 KB
643a69d @tj Started benchmarks
tj authored Aug 13, 2010
1
2 #include <stdio.h>
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 2, 2014
3 #include "bench/bench.h"
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
4 #include "src/list.h"
5
6 static void
7 bm(char *label, void (*fn)()) {
a566f0c @tj More benchmarks
tj authored Aug 13, 2010
8 printf(" %18s", label);
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
9 fflush(stdout);
10 fn();
11 }
12
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
13 static int nnodes = 10000000;
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 3, 2014
14 static float startTime;
15
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
16
17 static void
18 start() {
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 3, 2014
19 startTime = cpu();
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
20 }
21
22 static void
23 stop() {
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 3, 2014
24 float duration = cpu() - startTime;
ffb160f @tj Added unshift benchmark
tj authored Aug 13, 2010
25 printf(": \x1b[32m%.4f\x1b[0ms\n", duration);
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
26 }
27
28 static void
ff0b832 @tj push -> rpush
tj authored Apr 15, 2011
29 bm_rpush() {
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
30 start();
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
31 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 27, 2010
32 list_t *list = list_new();
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
33 while (n--) {
ff0b832 @tj push -> rpush
tj authored Apr 15, 2011
34 list_rpush(list, list_node_new("foo"));
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
35 }
36 stop();
37 }
38
ffb160f @tj Added unshift benchmark
tj authored Aug 14, 2010
39 static void
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
40 bm_lpush() {
ffb160f @tj Added unshift benchmark
tj authored Aug 14, 2010
41 start();
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
42 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
43 list_t *list = list_new();
ffb160f @tj Added unshift benchmark
tj authored Aug 14, 2010
44 while (n--) {
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
45 list_lpush(list, list_node_new("foo"));
ffb160f @tj Added unshift benchmark
tj authored Aug 14, 2010
46 }
47 stop();
48 }
49
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
50 static void
51 bm_find() {
52 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
53 list_t *list = list_new();
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
54 while (n--) {
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
55 list_lpush(list, list_node_new("foo"));
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
56 }
ff0b832 @tj push -> rpush
tj authored Apr 15, 2011
57 list_rpush(list, list_node_new("bar"));
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
58 start();
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
59 list_find(list, "bar");
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
60 stop();
61 }
62
63 static void
64 bm_iterate() {
65 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
66 list_t *list = list_new();
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
67 while (n--) {
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
68 list_lpush(list, list_node_new("foo"));
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
69 }
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
70 list_iterator_t *it = list_iterator_new(list, LIST_HEAD);
71 list_node_t *node;
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
72 start();
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
73 while ((node = list_iterator_next(it)))
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
74 ;
75 stop();
76 }
77
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
78 static void
1a50cc1 @tj pop -> rpop
tj authored Apr 15, 2011
79 bm_rpop() {
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
80 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
81 list_t *list = list_new();
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
82 while (n--) {
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
83 list_lpush(list, list_node_new("foo"));
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
84 }
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
85 list_node_t *node;
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
86 start();
1a50cc1 @tj pop -> rpop
tj authored Apr 15, 2011
87 while ((node = list_rpop(list)))
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
88 ;
89 stop();
90 }
91
92 static void
3240b6d @tj shift -> lpop
tj authored Apr 15, 2011
93 bm_lpop() {
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
94 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
95 list_t *list = list_new();
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
96 while (n--) {
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
97 list_lpush(list, list_node_new("foo"));
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
98 }
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
99 list_node_t *node;
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
100 start();
3240b6d @tj shift -> lpop
tj authored Apr 15, 2011
101 while ((node = list_lpop(list)))
8ad23ff @tj Added pop/shift benchmarks
tj authored Aug 23, 2010
102 ;
103 stop();
104 }
105
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
106 static list_t *list;
3981668 @tj More benchmarks
tj authored Aug 21, 2010
107
108 static void
109 bm_at() {
110 start();
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
111 list_at(list, 100000);
3981668 @tj More benchmarks
tj authored Aug 21, 2010
112 stop();
113 }
114
115 static void
116 bm_at2() {
117 start();
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
118 list_at(list, 1000000);
3981668 @tj More benchmarks
tj authored Aug 21, 2010
119 stop();
120 }
121
122 static void
123 bm_at3() {
124 start();
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
125 list_at(list, -100000);
3981668 @tj More benchmarks
tj authored Aug 21, 2010
126 stop();
127 }
128
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
129 int
f2cc53c @stephenmathieson benchmark: Fix 'unused parameter' warning
stephenmathieson authored Jun 2, 2014
130 main(void){
3981668 @tj More benchmarks
tj authored Aug 21, 2010
131 int n = nnodes;
cef669d @tj Fixed benchmarks after rename
tj authored Nov 28, 2010
132 list = list_new();
3f0ef1d @tj unshift -> lpush
tj authored Apr 15, 2011
133 while (n--) list_lpush(list, list_node_new("foo"));
a566f0c @tj More benchmarks
tj authored Aug 14, 2010
134 puts("\n 10,000,000 nodes\n");
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 3, 2014
135 bm("lpush", bm_lpush);
1a50cc1 @tj pop -> rpop
tj authored Apr 15, 2011
136 bm("rpush", bm_rpush);
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 3, 2014
137 bm("lpop", bm_lpop);
138 bm("rpop", bm_rpop);
139 bm("find (last node)", bm_find);
140 bm("iterate", bm_iterate);
141 bm("at(100,000)", bm_at);
142 bm("at(1,000,000)", bm_at2);
143 bm("at(-100,000)", bm_at3);
643a69d @tj Started benchmarks
tj authored Aug 14, 2010
144 puts("");
145 return 0;
b973c40 @stephenmathieson benchmark: Use clibs/bench for CPU time
stephenmathieson authored Jun 3, 2014
146 }
Something went wrong with that request. Please try again.