Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
2923a481
Commit
2923a481
authored
Jan 07, 2014
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multithreaded tests are reenabled
parent
15bf6675
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
106 deletions
+136
-106
benchmark.h
include/benchmark/benchmark.h
+16
-6
macros.h
include/benchmark/macros.h
+1
-0
benchmark.cc
src/benchmark.cc
+98
-92
benchmark_test.cc
test/benchmark_test.cc
+21
-8
No files found.
include/benchmark/benchmark.h
View file @
2923a481
...
@@ -129,6 +129,7 @@ static void BM_MultiThreaded(benchmark::State& state) {
...
@@ -129,6 +129,7 @@ static void BM_MultiThreaded(benchmark::State& state) {
// Teardown code here.
// Teardown code here.
}
}
}
}
BENCHMARK(BM_MultiThreaded)->Threads(4);
*/
*/
#ifndef BENCHMARK_BENCHMARK_H_
#ifndef BENCHMARK_BENCHMARK_H_
...
@@ -137,6 +138,7 @@ static void BM_MultiThreaded(benchmark::State& state) {
...
@@ -137,6 +138,7 @@ static void BM_MultiThreaded(benchmark::State& state) {
#include <stdint.h>
#include <stdint.h>
#include <functional>
#include <functional>
#include <memory>
#include <string>
#include <string>
#include <vector>
#include <vector>
...
@@ -226,6 +228,7 @@ class State {
...
@@ -226,6 +228,7 @@ class State {
private
:
private
:
class
FastClock
;
class
FastClock
;
struct
SharedState
;
struct
SharedState
;
struct
ThreadStats
;
State
(
FastClock
*
clock
,
SharedState
*
s
,
int
t
);
State
(
FastClock
*
clock
,
SharedState
*
s
,
int
t
);
bool
StartRunning
();
bool
StartRunning
();
...
@@ -234,7 +237,10 @@ class State {
...
@@ -234,7 +237,10 @@ class State {
void
NewInterval
();
void
NewInterval
();
bool
AllStarting
();
bool
AllStarting
();
static
void
*
RunWrapper
(
void
*
arg
);
void
Run
();
void
Run
();
void
RunAsThread
();
void
Wait
();
enum
EState
{
enum
EState
{
STATE_INITIAL
,
// KeepRunning hasn't been called
STATE_INITIAL
,
// KeepRunning hasn't been called
...
@@ -242,7 +248,9 @@ class State {
...
@@ -242,7 +248,9 @@ class State {
STATE_RUNNING
,
// Running and being timed
STATE_RUNNING
,
// Running and being timed
STATE_STOPPING
,
// Not being timed but waiting for other threads
STATE_STOPPING
,
// Not being timed but waiting for other threads
STATE_STOPPED
,
// Stopped
STATE_STOPPED
,
// Stopped
}
state_
;
};
EState
state_
;
FastClock
*
clock_
;
FastClock
*
clock_
;
...
@@ -250,6 +258,8 @@ class State {
...
@@ -250,6 +258,8 @@ class State {
// BenchmarkInstance
// BenchmarkInstance
SharedState
*
shared_
;
SharedState
*
shared_
;
pthread_t
thread_
;
// Custom label set by the user.
// Custom label set by the user.
std
::
string
label_
;
std
::
string
label_
;
...
@@ -274,6 +284,8 @@ class State {
...
@@ -274,6 +284,8 @@ class State {
// True if the current interval is the continuation of a previous one.
// True if the current interval is the continuation of a previous one.
bool
is_continuation_
;
bool
is_continuation_
;
std
::
unique_ptr
<
ThreadStats
>
stats_
;
friend
class
internal
::
Benchmark
;
friend
class
internal
::
Benchmark
;
DISALLOW_COPY_AND_ASSIGN
(
State
);
DISALLOW_COPY_AND_ASSIGN
(
State
);
};
};
...
@@ -345,8 +357,7 @@ class Benchmark {
...
@@ -345,8 +357,7 @@ class Benchmark {
// of some piece of code.
// of some piece of code.
// Run one instance of this benchmark concurrently in t threads.
// Run one instance of this benchmark concurrently in t threads.
// TODO(dominic): Allow multithreaded benchmarks
Benchmark
*
Threads
(
int
t
);
//Benchmark* Threads(int t);
// Pick a set of values T from [min_threads,max_threads].
// Pick a set of values T from [min_threads,max_threads].
// min_threads and max_threads are always included in T. Run this
// min_threads and max_threads are always included in T. Run this
...
@@ -360,10 +371,10 @@ class Benchmark {
...
@@ -360,10 +371,10 @@ class Benchmark {
// Foo in 4 threads
// Foo in 4 threads
// Foo in 8 threads
// Foo in 8 threads
// Foo in 16 threads
// Foo in 16 threads
//
Benchmark* ThreadRange(int min_threads, int max_threads);
Benchmark
*
ThreadRange
(
int
min_threads
,
int
max_threads
);
// Equivalent to ThreadRange(NumCPUs(), NumCPUs())
// Equivalent to ThreadRange(NumCPUs(), NumCPUs())
//
Benchmark* ThreadPerCpu();
Benchmark
*
ThreadPerCpu
();
// TODO(dominic): Control whether or not real-time is used for this benchmark
// TODO(dominic): Control whether or not real-time is used for this benchmark
...
@@ -372,7 +383,6 @@ class Benchmark {
...
@@ -372,7 +383,6 @@ class Benchmark {
// Used inside the benchmark implementation
// Used inside the benchmark implementation
struct
Instance
;
struct
Instance
;
struct
ThreadStats
;
// Extract the list of benchmark instances that match the specified
// Extract the list of benchmark instances that match the specified
// regular expression.
// regular expression.
...
...
include/benchmark/macros.h
View file @
2923a481
...
@@ -36,6 +36,7 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
...
@@ -36,6 +36,7 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
#define CHECK(b) do { if (!(b)) assert(false); } while(0)
#define CHECK(b) do { if (!(b)) assert(false); } while(0)
#define CHECK_EQ(a, b) CHECK((a) == (b))
#define CHECK_EQ(a, b) CHECK((a) == (b))
#define CHECK_NE(a, b) CHECK((a) != (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
#define CHECK_LE(a, b) CHECK((a) <= (b))
#define CHECK_LE(a, b) CHECK((a) <= (b))
#define CHECK_GT(a, b) CHECK((a) > (b))
#define CHECK_GT(a, b) CHECK((a) > (b))
...
...
src/benchmark.cc
View file @
2923a481
This diff is collapsed.
Click to expand it.
test/benchmark_test.cc
View file @
2923a481
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <math.h>
#include <math.h>
#include <stdint.h>
#include <stdint.h>
#include <iostream>
#include <limits>
#include <limits>
#include <list>
#include <list>
#include <map>
#include <map>
...
@@ -33,7 +34,8 @@ std::set<int> ConstructRandomSet(int size) {
...
@@ -33,7 +34,8 @@ std::set<int> ConstructRandomSet(int size) {
return
s
;
return
s
;
}
}
static
std
::
vector
<
int
>*
test_vector
=
NULL
;
pthread_mutex_t
test_vector_mu
;
std
::
vector
<
int
>*
test_vector
=
nullptr
;
}
// end namespace
}
// end namespace
...
@@ -57,7 +59,7 @@ static void BM_CalculatePiRange(benchmark::State& state) {
...
@@ -57,7 +59,7 @@ static void BM_CalculatePiRange(benchmark::State& state) {
state
.
SetLabel
(
ss
.
str
());
state
.
SetLabel
(
ss
.
str
());
}
}
BENCHMARK_RANGE
(
BM_CalculatePiRange
,
1
,
1024
*
1024
);
BENCHMARK_RANGE
(
BM_CalculatePiRange
,
1
,
1024
*
1024
);
/*
static
void
BM_CalculatePi
(
benchmark
::
State
&
state
)
{
static
void
BM_CalculatePi
(
benchmark
::
State
&
state
)
{
static
const
int
depth
=
1024
;
static
const
int
depth
=
1024
;
double
pi
ATTRIBUTE_UNUSED
=
0.0
;
double
pi
ATTRIBUTE_UNUSED
=
0.0
;
...
@@ -68,7 +70,7 @@ static void BM_CalculatePi(benchmark::State& state) {
...
@@ -68,7 +70,7 @@ static void BM_CalculatePi(benchmark::State& state) {
BENCHMARK
(
BM_CalculatePi
)
->
Threads
(
8
);
BENCHMARK
(
BM_CalculatePi
)
->
Threads
(
8
);
BENCHMARK
(
BM_CalculatePi
)
->
ThreadRange
(
1
,
32
);
BENCHMARK
(
BM_CalculatePi
)
->
ThreadRange
(
1
,
32
);
BENCHMARK
(
BM_CalculatePi
)
->
ThreadPerCpu
();
BENCHMARK
(
BM_CalculatePi
)
->
ThreadPerCpu
();
*/
static
void
BM_SetInsert
(
benchmark
::
State
&
state
)
{
static
void
BM_SetInsert
(
benchmark
::
State
&
state
)
{
while
(
state
.
KeepRunning
())
{
while
(
state
.
KeepRunning
())
{
state
.
PauseTiming
();
state
.
PauseTiming
();
...
@@ -107,16 +109,27 @@ static void BM_StringCompare(benchmark::State& state) {
...
@@ -107,16 +109,27 @@ static void BM_StringCompare(benchmark::State& state) {
BENCHMARK
(
BM_StringCompare
)
->
Range
(
1
,
1
<<
20
);
BENCHMARK
(
BM_StringCompare
)
->
Range
(
1
,
1
<<
20
);
static
void
BM_SetupTeardown
(
benchmark
::
State
&
state
)
{
static
void
BM_SetupTeardown
(
benchmark
::
State
&
state
)
{
if
(
state
.
thread_index
==
0
)
if
(
state
.
thread_index
==
0
)
{
pthread_mutex_init
(
&
test_vector_mu
,
nullptr
);
// No need to lock test_vector_mu here as this is running single-threaded.
test_vector
=
new
std
::
vector
<
int
>
();
test_vector
=
new
std
::
vector
<
int
>
();
while
(
state
.
KeepRunning
())
}
test_vector
->
push_back
(
0
);
int
i
=
0
;
while
(
state
.
KeepRunning
())
{
pthread_mutex_lock
(
&
test_vector_mu
);
if
(
i
%
2
==
0
)
test_vector
->
push_back
(
i
);
else
test_vector
->
pop_back
();
pthread_mutex_unlock
(
&
test_vector_mu
);
++
i
;
}
if
(
state
.
thread_index
==
0
)
{
if
(
state
.
thread_index
==
0
)
{
delete
test_vector
;
delete
test_vector
;
test_vector
=
NULL
;
pthread_mutex_destroy
(
&
test_vector_mu
)
;
}
}
}
}
BENCHMARK
(
BM_SetupTeardown
);
BENCHMARK
(
BM_SetupTeardown
)
->
ThreadPerCpu
()
;
static
void
BM_LongTest
(
benchmark
::
State
&
state
)
{
static
void
BM_LongTest
(
benchmark
::
State
&
state
)
{
double
tracker
=
0.0
;
double
tracker
=
0.0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment