mirror of
https://github.com/google/benchmark.git
synced 2025-04-12 20:41:14 +08:00
Merge branch 'new-api' into api-merge
This commit is contained in:
commit
2627b85358
@ -11,7 +11,8 @@ if (NOT BENCHMARK_LOGGING_LEVEL STREQUAL "0")
|
||||
add_definitions(-DBENCHMARK_LOGGING_LEVEL=${BENCHMARK_LOGGING_LEVEL})
|
||||
endif()
|
||||
|
||||
# Enable the latest C++ standard possible
|
||||
# Try and enable C++11. Don't use C++14 because it doesn't work in some
|
||||
# configurations.
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(AddCXXCompilerFlag)
|
||||
include(CXXFeatureCheck)
|
||||
|
@ -26,7 +26,7 @@ void SleepForSeconds(double seconds) {
|
||||
SleepForMilliseconds(static_cast<int>(kNumMillisPerSecond * seconds));
|
||||
}
|
||||
#else // OS_WINDOWS
|
||||
void SleepForMicroseconds(int64_t microseconds) {
|
||||
void SleepForMicroseconds(int microseconds) {
|
||||
struct timespec sleep_time;
|
||||
sleep_time.tv_sec = microseconds / kNumMicrosPerSecond;
|
||||
sleep_time.tv_nsec = (microseconds % kNumMicrosPerSecond) * kNumNanosPerMicro;
|
||||
@ -35,11 +35,11 @@ void SleepForMicroseconds(int64_t microseconds) {
|
||||
}
|
||||
|
||||
void SleepForMilliseconds(int milliseconds) {
|
||||
SleepForMicroseconds(static_cast<int64_t>(milliseconds) * kNumMicrosPerMilli);
|
||||
SleepForMicroseconds(static_cast<int>(milliseconds) * kNumMicrosPerMilli);
|
||||
}
|
||||
|
||||
void SleepForSeconds(double seconds) {
|
||||
SleepForMicroseconds(static_cast<int64_t>(seconds * kNumMicrosPerSecond));
|
||||
SleepForMicroseconds(static_cast<int>(seconds * kNumMicrosPerSecond));
|
||||
}
|
||||
#endif // OS_WINDOWS
|
||||
} // end namespace benchmark
|
||||
|
@ -10,7 +10,6 @@ const int64_t kNumMicrosPerSecond = kNumMillisPerSecond * 1000LL;
|
||||
const int64_t kNumNanosPerMicro = 1000LL;
|
||||
const int64_t kNumNanosPerSecond = kNumNanosPerMicro * kNumMicrosPerSecond;
|
||||
|
||||
void SleepForMicroseconds(int64_t microseconds);
|
||||
void SleepForMilliseconds(int milliseconds);
|
||||
void SleepForSeconds(double seconds);
|
||||
} // end namespace benchmark
|
||||
|
@ -15,14 +15,16 @@
|
||||
#include "sysinfo.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h> // FreeBSD requires this be included before sysctl.h
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@ -56,7 +58,7 @@ int64_t EstimateCyclesPerSecond() {
|
||||
#if defined OS_LINUX || defined OS_CYGWIN
|
||||
// Helper function for reading an int from a file. Returns true if successful
|
||||
// and the memory location pointed to by value is set to the value read.
|
||||
bool ReadIntFromFile(const char* file, int* value) {
|
||||
bool ReadIntFromFile(const char* file, long* value) {
|
||||
bool ret = false;
|
||||
int fd = open(file, O_RDONLY);
|
||||
if (fd != -1) {
|
||||
@ -64,7 +66,7 @@ bool ReadIntFromFile(const char* file, int* value) {
|
||||
char* err;
|
||||
memset(line, '\0', sizeof(line));
|
||||
CHECK(read(fd, line, sizeof(line) - 1));
|
||||
const int temp_value = strtol(line, &err, 10);
|
||||
const long temp_value = strtol(line, &err, 10);
|
||||
if (line[0] != '\0' && (*err == '\n' || *err == '\0')) {
|
||||
*value = temp_value;
|
||||
ret = true;
|
||||
@ -79,7 +81,7 @@ void InitializeSystemInfo() {
|
||||
#if defined OS_LINUX || defined OS_CYGWIN
|
||||
char line[1024];
|
||||
char* err;
|
||||
int freq;
|
||||
long freq;
|
||||
|
||||
bool saw_mhz = false;
|
||||
|
||||
@ -121,13 +123,13 @@ void InitializeSystemInfo() {
|
||||
|
||||
double bogo_clock = 1.0;
|
||||
bool saw_bogo = false;
|
||||
int max_cpu_id = 0;
|
||||
long max_cpu_id = 0;
|
||||
int num_cpus = 0;
|
||||
line[0] = line[1] = '\0';
|
||||
int chars_read = 0;
|
||||
size_t chars_read = 0;
|
||||
do { // we'll exit when the last read didn't read anything
|
||||
// Move the next line to the beginning of the buffer
|
||||
const int oldlinelen = strlen(line);
|
||||
const size_t oldlinelen = strlen(line);
|
||||
if (sizeof(line) == oldlinelen + 1) // oldlinelen took up entire line
|
||||
line[0] = '\0';
|
||||
else // still other lines left to save
|
||||
@ -135,8 +137,8 @@ void InitializeSystemInfo() {
|
||||
// Terminate the new line, reading more if we can't find the newline
|
||||
char* newline = strchr(line, '\n');
|
||||
if (newline == NULL) {
|
||||
const int linelen = strlen(line);
|
||||
const int bytes_to_read = sizeof(line) - 1 - linelen;
|
||||
const size_t linelen = strlen(line);
|
||||
const size_t bytes_to_read = sizeof(line) - 1 - linelen;
|
||||
CHECK(bytes_to_read > 0); // because the memmove recovered >=1 bytes
|
||||
chars_read = read(fd, line + linelen, bytes_to_read);
|
||||
line[linelen + chars_read] = '\0';
|
||||
@ -165,7 +167,7 @@ void InitializeSystemInfo() {
|
||||
num_cpus++; // count up every time we see an "processor :" entry
|
||||
const char* freqstr = strchr(line, ':');
|
||||
if (freqstr) {
|
||||
const int cpu_id = strtol(freqstr + 1, &err, 10);
|
||||
const long cpu_id = strtol(freqstr + 1, &err, 10);
|
||||
if (freqstr[1] != '\0' && *err == '\0' && max_cpu_id < cpu_id)
|
||||
max_cpu_id = cpu_id;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
|
@ -170,7 +170,7 @@ class TestReporter : public benchmark::ConsoleReporter {
|
||||
|
||||
virtual ~TestReporter() {}
|
||||
|
||||
int GetCount() const {
|
||||
size_t GetCount() const {
|
||||
return count_;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user