diff options
Diffstat (limited to 'benchmarks/pthread_benchmark.cpp')
-rw-r--r-- | benchmarks/pthread_benchmark.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/benchmarks/pthread_benchmark.cpp b/benchmarks/pthread_benchmark.cpp index 92e59982..42023e04 100644 --- a/benchmarks/pthread_benchmark.cpp +++ b/benchmarks/pthread_benchmark.cpp | |||
@@ -47,6 +47,21 @@ static void BM_pthread_getspecific(int iters) { | |||
47 | } | 47 | } |
48 | BENCHMARK(BM_pthread_getspecific); | 48 | BENCHMARK(BM_pthread_getspecific); |
49 | 49 | ||
50 | static void BM_pthread_setspecific(int iters) { | ||
51 | StopBenchmarkTiming(); | ||
52 | pthread_key_t key; | ||
53 | pthread_key_create(&key, NULL); | ||
54 | StartBenchmarkTiming(); | ||
55 | |||
56 | for (int i = 0; i < iters; ++i) { | ||
57 | pthread_setspecific(key, NULL); | ||
58 | } | ||
59 | |||
60 | StopBenchmarkTiming(); | ||
61 | pthread_key_delete(key); | ||
62 | } | ||
63 | BENCHMARK(BM_pthread_setspecific); | ||
64 | |||
50 | static void DummyPthreadOnceInitFunction() { | 65 | static void DummyPthreadOnceInitFunction() { |
51 | } | 66 | } |
52 | 67 | ||
@@ -137,3 +152,80 @@ static void BM_pthread_rw_lock_write(int iters) { | |||
137 | pthread_rwlock_destroy(&lock); | 152 | pthread_rwlock_destroy(&lock); |
138 | } | 153 | } |
139 | BENCHMARK(BM_pthread_rw_lock_write); | 154 | BENCHMARK(BM_pthread_rw_lock_write); |
155 | |||
156 | static void* IdleThread(void*) { | ||
157 | return NULL; | ||
158 | } | ||
159 | |||
160 | static void BM_pthread_create(int iters) { | ||
161 | StopBenchmarkTiming(); | ||
162 | pthread_t thread; | ||
163 | |||
164 | for (int i = 0; i < iters; ++i) { | ||
165 | StartBenchmarkTiming(); | ||
166 | pthread_create(&thread, NULL, IdleThread, NULL); | ||
167 | StopBenchmarkTiming(); | ||
168 | pthread_join(thread, NULL); | ||
169 | } | ||
170 | } | ||
171 | BENCHMARK(BM_pthread_create); | ||
172 | |||
173 | static void* RunThread(void*) { | ||
174 | StopBenchmarkTiming(); | ||
175 | return NULL; | ||
176 | } | ||
177 | |||
178 | static void BM_pthread_create_and_run(int iters) { | ||
179 | StopBenchmarkTiming(); | ||
180 | pthread_t thread; | ||
181 | |||
182 | for (int i = 0; i < iters; ++i) { | ||
183 | StartBenchmarkTiming(); | ||
184 | pthread_create(&thread, NULL, RunThread, NULL); | ||
185 | pthread_join(thread, NULL); | ||
186 | } | ||
187 | } | ||
188 | BENCHMARK(BM_pthread_create_and_run); | ||
189 | |||
190 | static void* ExitThread(void*) { | ||
191 | StartBenchmarkTiming(); | ||
192 | pthread_exit(NULL); | ||
193 | } | ||
194 | |||
195 | static void BM_pthread_exit_and_join(int iters) { | ||
196 | StopBenchmarkTiming(); | ||
197 | pthread_t thread; | ||
198 | |||
199 | for (int i = 0; i < iters; ++i) { | ||
200 | pthread_create(&thread, NULL, ExitThread, NULL); | ||
201 | pthread_join(thread, NULL); | ||
202 | StopBenchmarkTiming(); | ||
203 | } | ||
204 | } | ||
205 | BENCHMARK(BM_pthread_exit_and_join); | ||
206 | |||
207 | static void BM_pthread_key_create(int iters) { | ||
208 | StopBenchmarkTiming(); | ||
209 | pthread_key_t key; | ||
210 | |||
211 | for (int i = 0; i < iters; ++i) { | ||
212 | StartBenchmarkTiming(); | ||
213 | pthread_key_create(&key, NULL); | ||
214 | StopBenchmarkTiming(); | ||
215 | pthread_key_delete(key); | ||
216 | } | ||
217 | } | ||
218 | BENCHMARK(BM_pthread_key_create); | ||
219 | |||
220 | static void BM_pthread_key_delete(int iters) { | ||
221 | StopBenchmarkTiming(); | ||
222 | pthread_key_t key; | ||
223 | |||
224 | for (int i = 0; i < iters; ++i) { | ||
225 | pthread_key_create(&key, NULL); | ||
226 | StartBenchmarkTiming(); | ||
227 | pthread_key_delete(key); | ||
228 | StopBenchmarkTiming(); | ||
229 | } | ||
230 | } | ||
231 | BENCHMARK(BM_pthread_key_delete); | ||