Skip to content

Commit

Permalink
Merge branch 'master' of github.com:google/benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Hofmann committed Oct 25, 2014
2 parents 3e9264d + f9ef4f4 commit b04211c
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Dominic Hamon <[email protected]>
Eugene Zhuk <[email protected]>
Felix Homann <[email protected]>
Google Inc.
JianXiong Zhou <[email protected]>
Lei Xu <[email protected]>
Matt Clarkson <[email protected]>
Oleksandr Sochka <[email protected]>
Expand Down
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ project (benchmark)
# Make sure we can import out CMake functions
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Resolve dependent packages
find_package(Threads REQUIRED)

# Import and build Google Test
include(ExternalProject)
set_directory_properties(properties EP_PREFIX "${CMAKE_BINARY_DIR}/third_party")
Expand Down Expand Up @@ -40,6 +37,7 @@ add_cxx_compiler_flag(-Wall)
add_cxx_compiler_flag(-Wshadow)
add_cxx_compiler_flag(-Werror)
add_cxx_compiler_flag(-pedantic-errors)
add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)

# Release flags
add_cxx_compiler_flag(-fno-strict-aliasing RELEASE)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ David Coeurjolly <[email protected]>
Dominic Hamon <[email protected]>
Eugene Zhuk <[email protected]>
Felix Homann <[email protected]>
JianXiong Zhou <[email protected]>
Lei Xu <[email protected]>
Matt Clarkson <[email protected]>
Oleksandr Sochka <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion cmake/AddCXXCompilerFlag.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function(add_cxx_compiler_flag FLAG)
if(${SANITIZED_FLAG})
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
string(TOUPPER "${VARIANT}" VARIANT)
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS}${VARIANT} ${FLAG}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
endif()
endfunction()

11 changes: 8 additions & 3 deletions cmake/CXXFeatureCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ function(cxx_feature_check FILE)
string(TOUPPER ${FILE} VAR)
string(TOUPPER "HAVE_${VAR}" FEATURE)
message("-- Performing Test ${FEATURE}")
try_run(RUN_${FEATURE} COMPILE_${FEATURE} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp)
try_run(RUN_${FEATURE} COMPILE_${FEATURE}
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp)
if(RUN_${FEATURE} EQUAL 0)
message("-- Performing Test ${FEATURE} -- Success")
message("-- Performing Test ${FEATURE} -- success")
set(HAVE_${VAR} 1 PARENT_SCOPE)
add_definitions(-DHAVE_${VAR})
else()
message("-- Performing Test ${FEATURE} -- Failed")
if(NOT COMPILE_${FEATURE})
message("-- Performing Test ${FEATURE} -- failed to compile")
else()
message("-- Performing Test ${FEATURE} -- compiled but failed to run")
endif()
endif()
endfunction()

2 changes: 1 addition & 1 deletion cmake/gnu_posix_regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int main() {
if (ec != 0) {
return ec;
}
return regexec(&re, str.c_str(), 0, NULL, 0) ? -1 : 0;
return regexec(&re, str.c_str(), 0, nullptr, 0) ? -1 : 0;
}

2 changes: 1 addition & 1 deletion cmake/posix_regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int main() {
if (ec != 0) {
return ec;
}
return regexec(&re, str.c_str(), 0, NULL, 0) ? -1 : 0;
return regexec(&re, str.c_str(), 0, nullptr, 0) ? -1 : 0;
}

4 changes: 3 additions & 1 deletion cmake/std_regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <string>
int main() {
const std::string str = "test0159";
const std::regex re("^[a-z]+[0-9]+$", std::regex_constants::extended | std::regex_constants::nosubs);
const std::regex re(
"^[a-z]+[0-9]+$",
std::regex_constants::extended | std::regex_constants::nosubs);
return std::regex_search(str, re) ? 0 : -1;
}

2 changes: 2 additions & 0 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ BENCHMARK(BM_MultiThreaded)->Threads(4);
#include <string>
#include <thread>
#include <vector>
#include <mutex>

#include "macros.h"

Expand Down Expand Up @@ -462,6 +463,7 @@ class Benchmark {
std::vector<int> rangeX_;
std::vector<int> rangeY_;
std::vector<int> thread_counts_;
std::mutex mutex_;

// Special value placed in thread_counts_ to stand for NumCPUs()
static const int kNumCpuMarker = -1;
Expand Down
24 changes: 12 additions & 12 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ inline std::string HumanReadableNumber(double n) {
// For non-dense Range, intermediate values are powers of kRangeMultiplier.
static const int kRangeMultiplier = 8;

static std::mutex benchmark_mutex;
std::mutex starting_mutex;
std::condition_variable starting_cv;

Expand Down Expand Up @@ -326,6 +325,7 @@ class BenchmarkFamilies {
~BenchmarkFamilies();

std::vector<Benchmark*> families_;
std::mutex mutex_;
};

BenchmarkFamilies* BenchmarkFamilies::GetInstance() {
Expand All @@ -342,7 +342,7 @@ BenchmarkFamilies::~BenchmarkFamilies() {
}

int BenchmarkFamilies::AddBenchmark(Benchmark* family) {
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
// This loop attempts to reuse an entry that was previously removed to avoid
// unncessary growth of the vector.
for (size_t index = 0; index < families_.size(); ++index) {
Expand All @@ -357,7 +357,7 @@ int BenchmarkFamilies::AddBenchmark(Benchmark* family) {
}

void BenchmarkFamilies::RemoveBenchmark(int index) {
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
families_[index] = NULL;
// Don't shrink families_ here, we might be called by the destructor of
// BenchmarkFamilies which iterates over the vector.
Expand All @@ -374,7 +374,7 @@ void BenchmarkFamilies::FindBenchmarks(
return;
}

std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
for (internal::Benchmark* family : families_) {
if (family == nullptr) continue; // Family was deleted

Expand Down Expand Up @@ -707,7 +707,7 @@ Benchmark::~Benchmark() {
}

Benchmark* Benchmark::Arg(int x) {
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
rangeX_.push_back(x);
return this;
}
Expand All @@ -716,21 +716,21 @@ Benchmark* Benchmark::Range(int start, int limit) {
std::vector<int> arglist;
AddRange(&arglist, start, limit, kRangeMultiplier);

std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
for (size_t i = 0; i < arglist.size(); ++i) rangeX_.push_back(arglist[i]);
return this;
}

Benchmark* Benchmark::DenseRange(int start, int limit) {
CHECK_GE(start, 0);
CHECK_LE(start, limit);
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
for (int arg = start; arg <= limit; ++arg) rangeX_.push_back(arg);
return this;
}

Benchmark* Benchmark::ArgPair(int x, int y) {
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
rangeX_.push_back(x);
rangeY_.push_back(y);
return this;
Expand All @@ -741,7 +741,7 @@ Benchmark* Benchmark::RangePair(int lo1, int hi1, int lo2, int hi2) {
AddRange(&arglist1, lo1, hi1, kRangeMultiplier);
AddRange(&arglist2, lo2, hi2, kRangeMultiplier);

std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
rangeX_.resize(arglist1.size());
std::copy(arglist1.begin(), arglist1.end(), rangeX_.begin());
rangeY_.resize(arglist2.size());
Expand All @@ -756,7 +756,7 @@ Benchmark* Benchmark::Apply(void (*custom_arguments)(Benchmark* benchmark)) {

Benchmark* Benchmark::Threads(int t) {
CHECK_GT(t, 0);
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
thread_counts_.push_back(t);
return this;
}
Expand All @@ -765,13 +765,13 @@ Benchmark* Benchmark::ThreadRange(int min_threads, int max_threads) {
CHECK_GT(min_threads, 0);
CHECK_GE(max_threads, min_threads);

std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
AddRange(&thread_counts_, min_threads, max_threads, 2);
return this;
}

Benchmark* Benchmark::ThreadPerCpu() {
std::lock_guard<std::mutex> l(benchmark_mutex);
std::lock_guard<std::mutex> l(mutex_);
thread_counts_.push_back(NumCPUs());
return this;
}
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
find_package(Threads REQUIRED)

# Demonstration executable
add_executable(benchmark_test benchmark_test.cc)
target_link_libraries(benchmark_test benchmark ${CMAKE_THREAD_LIBS_INIT})
Expand Down

0 comments on commit b04211c

Please sign in to comment.