mirror of
https://github.com/google/benchmark.git
synced 2025-03-05 06:40:09 +08:00
Merge pull request #137 from jll63/jleroy/vs2013-compatibility
Jleroy/vs2013 compatibility
This commit is contained in:
commit
7583ed9363
@ -27,12 +27,16 @@
|
||||
#if defined(__GNUC__)
|
||||
# define BENCHMARK_UNUSED __attribute__((unused))
|
||||
# define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline))
|
||||
# define BENCHMARK_NOEXCEPT noexcept
|
||||
#elif defined(_MSC_VER) && !defined(__clang__)
|
||||
# define BENCHMARK_UNUSED
|
||||
# define BENCHMARK_ALWAYS_INLINE __forceinline
|
||||
# define BENCHMARK_NOEXCEPT
|
||||
# define __func__ __FUNCTION__
|
||||
#else
|
||||
# define BENCHMARK_UNUSED
|
||||
# define BENCHMARK_ALWAYS_INLINE
|
||||
# define BENCHMARK_NOEXCEPT
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
@ -49,7 +49,7 @@ class BenchmarkReporter {
|
||||
|
||||
std::string benchmark_name;
|
||||
std::string report_label; // Empty if not set by benchmark.
|
||||
size_t iterations;
|
||||
int64_t iterations;
|
||||
double real_accumulated_time;
|
||||
double cpu_accumulated_time;
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "internal_macros.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#ifndef OS_WINDOWS
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
@ -40,7 +40,10 @@
|
||||
extern "C" uint64_t __rdtsc();
|
||||
#pragma intrinsic(__rdtsc)
|
||||
#endif
|
||||
|
||||
#ifndef OS_WINDOWS
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
namespace benchmark {
|
||||
// NOTE: only i386 and x86_64 have been well tested.
|
||||
|
@ -44,12 +44,6 @@ std::string FormatKV(std::string const& key, int64_t value) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string FormatKV(std::string const& key, std::size_t value) {
|
||||
std::stringstream ss;
|
||||
ss << '"' << key << "\": " << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
int64_t RoundDouble(double v) {
|
||||
return static_cast<int64_t>(v + 0.5);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ void BenchmarkReporter::ComputeStats(
|
||||
Stat1_d items_per_second_stat;
|
||||
// All repetitions should be run with the same number of iterations so we
|
||||
// can take this information from the first benchmark.
|
||||
std::size_t const run_iterations = reports.front().iterations;
|
||||
int64_t const run_iterations = reports.front().iterations;
|
||||
|
||||
// Populate the accumulators.
|
||||
for (Run const& run : reports) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include "internal_macros.h"
|
||||
|
||||
namespace benchmark {
|
||||
|
||||
@ -14,7 +15,7 @@ std::string HumanReadableNumber(double n);
|
||||
std::string StringPrintF(const char* format, ...);
|
||||
|
||||
inline std::ostream&
|
||||
StringCatImp(std::ostream& out) noexcept
|
||||
StringCatImp(std::ostream& out) BENCHMARK_NOEXCEPT
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ static double MyCPUUsageRUsage() {
|
||||
user.HighPart = user_time.dwHighDateTime;
|
||||
user.LowPart = user_time.dwLowDateTime;
|
||||
return (static_cast<double>(kernel.QuadPart) +
|
||||
static_cast<double>(user.QuadPart)) / 1.0E-7;
|
||||
static_cast<double>(user.QuadPart)) * 1e-7;
|
||||
#endif // OS_WINDOWS
|
||||
}
|
||||
|
||||
@ -394,6 +394,7 @@ int NumCPUs(void) {
|
||||
: nullptr)
|
||||
|
||||
bool CpuScalingEnabled() {
|
||||
#ifndef OS_WINDOWS
|
||||
// On Linux, the CPUfreq subsystem exposes CPU information as files on the
|
||||
// local file system. If reading the exported files fails, then we may not be
|
||||
// running on Linux, so we silently ignore all the read errors.
|
||||
@ -407,6 +408,7 @@ bool CpuScalingEnabled() {
|
||||
fclose(file);
|
||||
if (memprefix(buff, bytes_read, "performance") == nullptr) return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "benchmark/macros.h"
|
||||
#include "internal_macros.h"
|
||||
#include "walltime.h"
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <time.h>
|
||||
#include <winsock.h> // for timeval
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
@ -51,7 +58,7 @@ struct ChooseSteadyClock<false> {
|
||||
|
||||
struct ChooseClockType {
|
||||
#if defined(HAVE_STEADY_CLOCK)
|
||||
typedef typename ChooseSteadyClock<>::type type;
|
||||
typedef ChooseSteadyClock<>::type type;
|
||||
#else
|
||||
typedef std::chrono::high_resolution_clock type;
|
||||
#endif
|
||||
@ -92,7 +99,22 @@ private:
|
||||
|
||||
WallTime Slow() const {
|
||||
struct timeval tv;
|
||||
#if defined(OS_WINDOWS)
|
||||
FILETIME file_time;
|
||||
SYSTEMTIME system_time;
|
||||
ULARGE_INTEGER ularge;
|
||||
const unsigned __int64 epoch = 116444736000000000LL;
|
||||
|
||||
GetSystemTime(&system_time);
|
||||
SystemTimeToFileTime(&system_time, &file_time);
|
||||
ularge.LowPart = file_time.dwLowDateTime;
|
||||
ularge.HighPart = file_time.dwHighDateTime;
|
||||
|
||||
tv.tv_sec = (long)((ularge.QuadPart - epoch) / (10L * 1000 * 1000));
|
||||
tv.tv_usec = (long)(system_time.wMilliseconds * 1000);
|
||||
#else
|
||||
gettimeofday(&tv, nullptr);
|
||||
#endif
|
||||
return tv.tv_sec + tv.tv_usec * 1e-6;
|
||||
}
|
||||
|
||||
@ -100,8 +122,6 @@ private:
|
||||
static_assert(sizeof(float) <= sizeof(int32_t),
|
||||
"type sizes don't allow the drift_adjust hack");
|
||||
|
||||
static constexpr double kMaxErrorInterval = 100e-6;
|
||||
|
||||
WallTime base_walltime_;
|
||||
int64_t base_cycletime_;
|
||||
int64_t cycles_per_second_;
|
||||
@ -147,6 +167,7 @@ WallTimeImp::WallTimeImp()
|
||||
cycles_per_second_(0), seconds_per_cycle_(0.0),
|
||||
last_adjust_time_(0), drift_adjust_(0),
|
||||
max_interval_cycles_(0) {
|
||||
const double kMaxErrorInterval = 100e-6;
|
||||
cycles_per_second_ = static_cast<int64_t>(CyclesPerSecond());
|
||||
CHECK(cycles_per_second_ != 0);
|
||||
seconds_per_cycle_ = 1.0 / cycles_per_second_;
|
||||
@ -213,15 +234,27 @@ std::string DateTimeString(bool local) {
|
||||
typedef std::chrono::system_clock Clock;
|
||||
std::time_t now = Clock::to_time_t(Clock::now());
|
||||
char storage[128];
|
||||
std::size_t written;
|
||||
|
||||
std::tm timeinfo;
|
||||
std::memset(&timeinfo, 0, sizeof(std::tm));
|
||||
if (local) {
|
||||
localtime_r(&now, &timeinfo);
|
||||
#if defined(OS_WINDOWS)
|
||||
written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now));
|
||||
#else
|
||||
std::tm timeinfo;
|
||||
std::memset(&timeinfo, 0, sizeof(std::tm));
|
||||
::localtime_r(&now, &timeinfo);
|
||||
written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
||||
#endif
|
||||
} else {
|
||||
gmtime_r(&now, &timeinfo);
|
||||
#if defined(OS_WINDOWS)
|
||||
written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now));
|
||||
#else
|
||||
std::tm timeinfo;
|
||||
std::memset(&timeinfo, 0, sizeof(std::tm));
|
||||
::gmtime_r(&now, &timeinfo);
|
||||
written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
||||
#endif
|
||||
}
|
||||
std::size_t written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
||||
CHECK(written < arraysize(storage));
|
||||
((void)written); // prevent unused variable in optimized mode.
|
||||
return std::string(storage);
|
||||
|
Loading…
Reference in New Issue
Block a user