Skip to content

Commit

Permalink
Adding additional output data to table
Browse files Browse the repository at this point in the history
  • Loading branch information
zcobell committed Mar 29, 2020
1 parent 9e6c786 commit 1154a44
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 80 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ set(SMARTSTACK_VERSION_PATCH 0)
set(SMARTSTACK_VERSION_STRING ${SMARTSTACK_VERSION_MAJOR}.${SMARTSTACK_VERSION_MINOR}.${SMARTSTACK_VERSION_PATCH})
###########################################################################

OPTION( SMARTSTACK_AGGREGATE "Includes functions deeper in the stack in total time" OFF )
OPTION( SMARTSTACK_BUILDSHARED "Build shared object version of SmartStack" OFF )
IF( SMARTSTACK_BUILDSHARED )
SET( SMARTSTACK_LIBTYPE SHARED )
Expand Down Expand Up @@ -143,7 +142,7 @@ ENDIF(SMARTSTACK_BUILD_BENCHMARK)
# ABSEIL SWISS TABLES
###########################################################################
IF(NOT CYGWIN)
OPTION(SMARTSTACK_USE_ABSEIL_FLAT_MAP "Use the Abseil Swiss Tables to increase speed" ON)
OPTION(SMARTSTACK_USE_ABSEIL_FLAT_MAP "Use the Abseil Swiss Tables to increase speed" OFF)
IF(SMARTSTACK_USE_ABSEIL_FLAT_MAP)
if(MSVC)
# /wd4005 macro-redefinition
Expand Down Expand Up @@ -179,10 +178,6 @@ SET( SMARTSTACK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/libsmartstack/timer.cpp

ADD_LIBRARY( smartstack ${SMARTSTACK_LIBTYPE} ${SMARTSTACK_SOURCES} )

IF( SMARTSTACK_AGGREGATE )
TARGET_COMPILE_DEFINITIONS( smartstack PRIVATE "SMARTSTACK_AGGREGATE" )
ENDIF( SMARTSTACK_AGGREGATE )

SET_TARGET_PROPERTIES( smartstack PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles/smartstack )

SET(HEADER_LIST ${CMAKE_SOURCE_DIR}/libsmartstack/smartstack.h )
Expand Down
2 changes: 1 addition & 1 deletion bench/bench.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QT -= gui
CONFIG += c++11 console benchmark
CONFIG -= app_bundle

GOOGLE_BENCH_HOME = /opt/google/benchmark
GOOGLE_BENCH_HOME = /opt/google-benchmark

INCLUDEPATH += $$GOOGLE_BENCH_HOME/include
LIBS += -L$$GOOGLE_BENCH_HOME/lib -lbenchmark -pthread
Expand Down
28 changes: 27 additions & 1 deletion bench/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
#include "smartstack.h"

const size_t c_functionSize = 500;
std::chrono::high_resolution_clock::time_point t_init;
std::vector<std::string> functionList(c_functionSize);
std::vector<int> intList(c_functionSize);

void initializer() {
t_init = std::chrono::high_resolution_clock::now();
SmartStack::Stack::startSession("Benchmark");
SmartStack::Stack::startFunction("myfunction");
SmartStack::Stack::endFunction();
Expand Down Expand Up @@ -118,6 +120,28 @@ static void bench_lookupNewFunction(benchmark::State& state) {
state.SetItemsProcessed(state.iterations());
}

static void bench_startTimer(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(std::chrono::high_resolution_clock::now());
}
}

static void bench_endTimerAndCount(benchmark::State& state) {
while (state.KeepRunning()) {
std::chrono::high_resolution_clock::time_point b =
std::chrono::high_resolution_clock::now();
benchmark::DoNotOptimize(
std::chrono::duration_cast<std::chrono::microseconds>(b - t_init)
.count());
}
}

static void bench_hashString(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(std::hash<std::string>()("function_name"));
}
}

BENCHMARK(bench_lookupRandomExistingFunction);
BENCHMARK(bench_lookupSameExistingFunction);
BENCHMARK(bench_lookupNewFunction);
Expand All @@ -127,7 +151,9 @@ BENCHMARK(bench_compareInts);
BENCHMARK(bench_getFunctionPointer);
BENCHMARK(bench_getPointerAndStart);
BENCHMARK(bench_createFunctionString);

BENCHMARK(bench_startTimer);
BENCHMARK(bench_endTimerAndCount);
BENCHMARK(bench_hashString);

int main(int argc, char** argv) {
initializer();
Expand Down
10 changes: 7 additions & 3 deletions libsmartstack/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ void Function::startFunction() {
this->m_ncall++;
}

void Function::pauseFunction() { this->m_timer.stopClock(); }
void Function::pauseFunction() { this->m_timer.pause(); }

void Function::restartFunction() { this->m_timer.startClock(); }
void Function::restartFunction() { this->m_timer.restart(); }

long long Function::meanDuration() {
return this->m_timer.elapsed() / this->m_ncall;
}

long long Function::meanGlobalDuration() {
return this->m_timer.globalElapsed() / this->m_ncall;
}

void Function::endFunction() { this->m_timer.stopClock(); }

std::string Function::name() const { return m_name; }
std::string Function::name() const { return this->m_name; }

long long Function::numCalls() const { return this->m_ncall; }

Expand Down
1 change: 1 addition & 0 deletions libsmartstack/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Function {
void SMARTSTACK_EXPORT restartFunction();

long long SMARTSTACK_EXPORT meanDuration();
long long SMARTSTACK_EXPORT meanGlobalDuration();

Timer SMARTSTACK_EXPORT *timer();

Expand Down
Loading

0 comments on commit 1154a44

Please sign in to comment.