Skip to content

Commit

Permalink
Added benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
slavenf committed Feb 29, 2024
1 parent 9a699f0 commit 6824958
Show file tree
Hide file tree
Showing 11 changed files with 4,027 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.vscode/*

benchmark/*.out

benchmark/*.exe
benchmark/*.ilk
benchmark/*.obj
benchmark/*.pdb

test/*.out

test/*.exe
Expand Down
51 changes: 51 additions & 0 deletions benchmark/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef SFL_BENCHMARK_COMMON_HPP
#define SFL_BENCHMARK_COMMON_HPP

#include <string_view>

///////////////////////////////////////////////////////////////////////////////

template <typename T>
constexpr std::string_view name_of_type_raw()
{
#if defined(_MSC_VER)
return __FUNCSIG__;
#else
return __PRETTY_FUNCTION__;
#endif
}

template <typename T>
constexpr std::string_view name_of_type()
{
using namespace std::literals;

// idea from https://github.com/TheLartians/StaticTypeInfo/blob/master/include/static_type_info/type_name.h
auto for_double = name_of_type_raw<double>();
auto n_before = for_double.find("double"sv);
auto n_after = for_double.size() - (n_before + "double"sv.size());

auto str = name_of_type_raw<T>();
str.remove_prefix(n_before);
str.remove_suffix(n_after);
return str;
}

///////////////////////////////////////////////////////////////////////////////

template <typename Container, typename = void>
struct has_emplace_front : std::false_type {};

template <typename Container>
struct has_emplace_front
<
Container,
std::void_t<decltype(std::declval<Container>().emplace_front())>
> : std::true_type {};

template <typename Container>
inline constexpr bool has_emplace_front_v = has_emplace_front<Container>::value;

///////////////////////////////////////////////////////////////////////////////

#endif // SFL_BENCHMARK_COMMON_HPP
37 changes: 37 additions & 0 deletions benchmark/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# This is GNU makefile for Linux OS and GCC/Clang compiler
#

# C++ compiler
CXX = clang++

# C++ compiler flags
CXXFLAGS = -std=c++20 -Wall -Wextra -Wfatal-errors -I ../include -DNDEBUG -O3

# Command for removing all files and directories
RM_RF = rm -rf

# List of all source files that must be compiled and tested
SRCS := $(wildcard *.cpp)

# First rule
.PHONY: all
all:

# This function generates build rule for given source file.
# Usage: $(call generate_rules,source_file)
define generate_rules

.PHONY: $(basename $(1))
all: $(basename $(1))
$(basename $(1)):
$(CXX) $(CXXFLAGS) $(1) -o $(basename $(1)).out

endef

# Generate rules for all source files
$(foreach file,$(SRCS),$(eval $(call generate_rules,$(file))))

.PHONY: clean
clean:
$(RM_RF) *.out
43 changes: 43 additions & 0 deletions benchmark/makefile.msvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# This is GNU makefile for Windows OS and Visual C++ compiler
#

# Default shell used by GNU Make on Windows
SHELL = cmd

# C++ compiler
CXX = cl

# C++ compiler flags
CXXFLAGS = /std:c++20 /nologo /EHsc /W4 /WX /I ..\include /O2

# Command for removing all files and directories
RM_RF = del /f /s /q

# List of all source files that must be compiled and tested
SRCS := $(wildcard *.cpp)

# First rule
.PHONY: all
all:

# This function generates build rule for given source file.
# Usage: $(call generate_rules,source_file)
define generate_rules

.PHONY: $(basename $(1))
all: $(basename $(1))
$(basename $(1)):
$(CXX) $(CXXFLAGS) $(1)

endef

# Generate rules for all source files
$(foreach file,$(SRCS),$(eval $(call generate_rules,$(file))))

.PHONY: clean
clean:
$(RM_RF) *.exe
$(RM_RF) *.ilk
$(RM_RF) *.obj
$(RM_RF) *.pdb
Loading

0 comments on commit 6824958

Please sign in to comment.