Skip to content

Commit

Permalink
新增性能测试工具
Browse files Browse the repository at this point in the history
  • Loading branch information
zxffffffff committed Aug 13, 2024
1 parent 9a2f286 commit 5c50d9f
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 0 deletions.
1 change: 1 addition & 0 deletions sample-tools-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ find_package(GTest CONFIG REQUIRED)

add_executable (${PROJECT_NAME}
log_test.cpp
benchmark_test.cpp
crypto_test.cpp
snappy_test.cpp
zlib_test.cpp
Expand Down
42 changes: 42 additions & 0 deletions sample-tools-test/benchmark_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************
** MIT License
**
** Author : xiaofeng.zhu
** Support : [email protected], [email protected]
**
****************************************************************************/
#include <gtest/gtest.h>
#include "benchmark.h"

#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1900)
/* msvc兼容utf-8: https://support.microsoft.com/en-us/kb/980263 */
#if (_MSC_VER >= 1700)
#pragma execution_character_set("utf-8")
#endif
#pragma warning(disable : 4566)
#endif

TEST(benchmark, once)
{
for (int i = 0; i < Hardware::GetCPUs(); ++i)
{
double use_ms = Benchmark::RunOnce();
double score = Benchmark::Score(use_ms);

std::cout << "benchmark score: " << score << std::endl;
if (use_ms < 100)
ASSERT_GT(score, 0);
else if (use_ms > 100)
ASSERT_LT(score, 0);
else /* 100 */
ASSERT_EQ(score, 0);
}
}

TEST(benchmark, multi_thread)
{
double score = Benchmark::RunMultiThread(3);

std::cout << "benchmark multi_thread score: " << score << std::endl;
ASSERT_NE(score, 0);
}
1 change: 1 addition & 0 deletions sample-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ file(GLOB_RECURSE include_headers
hardware.h
chrono.h
log.h
benchmark.h
interface/crypto_interface.h
interface/compression_interface.h
interface/threadpool_interface.h
Expand Down
Loading

0 comments on commit 5c50d9f

Please sign in to comment.