Browse Source

feat: Benchmark module

master
Dnomd343 2 years ago
parent
commit
0b1265128e
  1. 6
      src/CMakeLists.txt
  2. 1
      src/benchmark/CMakeLists.txt
  3. 39
      src/benchmark/benchmark.cc
  4. 18
      src/benchmark/benchmark.h
  5. 9
      src/main.cc

6
src/CMakeLists.txt

@ -15,6 +15,8 @@ include_directories(fast_cal)
include_directories(graph)
include_directories(benchmark)
################################################
add_subdirectory(utils)
@ -30,6 +32,8 @@ add_subdirectory(fast_cal)
add_subdirectory(graph)
add_subdirectory(benchmark)
################################################
add_executable(klotski main.cc)
@ -49,6 +53,8 @@ target_link_libraries(klotski fast_cal)
target_link_libraries(klotski graph)
target_link_libraries(klotski benchmark)
target_link_libraries(klotski pthread)
################################################

1
src/benchmark/CMakeLists.txt

@ -0,0 +1 @@
add_library(benchmark benchmark.cc)

39
src/benchmark/benchmark.cc

@ -0,0 +1,39 @@
#include "benchmark.h"
#include "basic_ranges.h"
const char split_line[] = "------------------------";
void Benchmark::basic_ranges(std::ostream &out) {
out << split_line << std::endl;
out << "Basic Ranges Benchmark" << std::endl;
if (BasicRanges::status() != BasicRanges::NO_INIT) {
out << "already built -> skip" << std::endl;
out << split_line << std::endl;
return;
}
auto start = clock();
BasicRanges::build();
// time_ms(start, out);
// out << time_ms_(start);
out << time_ms_str(start);
out << std::endl << split_line << std::endl;
}
long Benchmark::time_ms_(clock_t start) {
return (clock() - start) * 1000 / CLOCKS_PER_SEC;
}
void Benchmark::time_ms(clock_t start, std::ostream &out) {
out << (clock() - start) * 1000 / CLOCKS_PER_SEC << "ms";
}
void Benchmark::time_us(clock_t start, std::ostream &out) {
out << (clock() - start) * 1000000 / CLOCKS_PER_SEC << "us";
}
std::string Benchmark::time_ms_str(clock_t start) {
return std::string("\033[32m") + std::to_string((clock() - start) * 1000 / CLOCKS_PER_SEC) + "ms\033[0m";
}

18
src/benchmark/benchmark.h

@ -0,0 +1,18 @@
#pragma once
#include <ostream>
class Benchmark {
public:
static void basic_ranges(std::ostream &out);
static inline void time_ms(clock_t start, std::ostream &out);
static inline void time_us(clock_t start, std::ostream &out);
static inline long time_ms_(clock_t start);
static inline std::string time_ms_str(clock_t start);
};

9
src/main.cc

@ -10,6 +10,8 @@
#include "common.h"
#include "graph.h"
#include "benchmark.h"
#include <thread>
#include <algorithm>
#include <unistd.h>
@ -18,6 +20,13 @@
//int main(int argc, char *argv[]) {
int main() {
// BasicRanges::build();
Benchmark::basic_ranges(std::cout);
return 0;
BasicRanges::build();
// AllCases::build();

Loading…
Cancel
Save