File tree Expand file tree Collapse file tree
include/libtokenizer/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ target_include_directories(pytokenizer_compile_config
2323add_subdirectory (csrc/src/core )
2424add_subdirectory (csrc/bindings )
2525add_subdirectory (test )
26+ add_subdirectory (benchmarks )
2627
2728add_library (pytokenizer INTERFACE )
2829target_link_libraries (pytokenizer INTERFACE pytokenizer_core )
Original file line number Diff line number Diff line change 1+ project (benchmarks LANGUAGES CXX )
2+
3+ # FETCH CONTENT ---------------------------------
4+ include (FetchContent )
5+ set (FETCHCONTENT_TRY_FIND_PACKAGE TRUE )
6+
7+ FetchContent_Declare (
8+ benchmark
9+ GIT_REPOSITORY https://github.com/google/benchmark.git
10+ GIT_TAG v1.9.0
11+ GIT_SHALLOW TRUE
12+ FIND_PACKAGE_ARGS CONFIG
13+ )
14+ FetchContent_MakeAvailable (benchmark)
15+
16+ # EXECUTABLES ---------------------------------
17+ add_executable (bench bench.cpp )
18+ target_link_libraries (bench
19+ PRIVATE pytokenizer benchmark::benchmark
20+ )
Original file line number Diff line number Diff line change 1+ #include < benchmark/benchmark.h>
2+ #include " libtokenizer/libtokenizer.hpp"
3+
4+ void register_bench (const std::string& name) {
5+ benchmark::RegisterBenchmark (
6+ name,
7+ [](benchmark::State& state) {
8+ for (auto _ : state) {
9+ pytokenizer::core::Tokenizer tokenizer;
10+ tokenizer.foo ();
11+ }
12+ });
13+ }
14+
15+ int main (int argc, char ** argv) {
16+ benchmark::Initialize (&argc, argv);
17+ register_bench (" foo" );
18+
19+ benchmark::RunSpecifiedBenchmarks ();
20+ return 0 ;
21+ }
Original file line number Diff line number Diff line change 11#pragma once
22
3+ #include < string>
4+
35namespace pytokenizer {
46namespace core {
57
68class Tokenizer {
79public:
8- void foo ();
10+ std::string foo ();
911};
1012
1113} // namespace core
Original file line number Diff line number Diff line change 44namespace pytokenizer {
55namespace core {
66
7- void Tokenizer::foo () { std::cout << " foo" << std::endl ; }
7+ std::string Tokenizer::foo () { return " foo" ; }
88
99} // namespace core
1010} // namespace pytokenizer
Original file line number Diff line number Diff line change 66
77int main () {
88 pytokenizer::core::Tokenizer tokenizer;
9- tokenizer.foo ();
9+ std::cout << tokenizer.foo () << std::endl ;
1010 return 0 ;
1111}
You can’t perform that action at this time.
0 commit comments