From e738c261297118877cae0c2c0f856b5717aa0f21 Mon Sep 17 00:00:00 2001 From: owt5008137 Date: Sat, 1 Apr 2017 20:55:37 +0800 Subject: [PATCH] using CI to run benchmark --- .travis.yml | 7 +-- CMakeLists.txt | 4 +- LICENSE | 2 +- README.md | 39 ++++++++------ appveyor.yml | 16 +++--- doc/md/000_DESCRIPTION.md | 26 +++++++-- doc/md/010_INSTALL.md | 53 ++++++++++++------- doc/md/020_USAGE.md | 29 +++++----- doc/md/050_NOTICE.md | 5 +- doc/md/060_DEVELOPER.md | 5 +- doc/md/070_HISTORY.md | 30 +++++++++++ doc/md/080_CONSTRIBUTOR.md | 9 ++++ doc/md/080_SCHEDUAL.md | 7 --- doc/reports/linux_start_benchmark.sh | 23 -------- doc/reports/windows_start_benchmark.bat | 25 --------- sample/CMakeLists.txt | 19 ++++++- sample/sample_benchmark_coroutine.cpp | 13 +++++ sample/sample_benchmark_coroutine_malloc.cpp | 7 +++ .../sample_benchmark_coroutine_mem_pool.cpp | 7 +++ sample/sample_benchmark_task.cpp | 13 +++++ sample/sample_benchmark_task_malloc.cpp | 7 +++ sample/sample_benchmark_task_mem_pool.cpp | 7 +++ test/CMakeLists.txt | 8 ++- 23 files changed, 235 insertions(+), 126 deletions(-) create mode 100644 doc/md/070_HISTORY.md create mode 100644 doc/md/080_CONSTRIBUTOR.md delete mode 100644 doc/md/080_SCHEDUAL.md diff --git a/.travis.yml b/.travis.yml index ca5aaad..b963ec0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ env: global: - LANG="zh_CN.UTF-8" - CMAKE_PREFIX=$HOME/prebuilt/cmake ; - - CMAKE_VERSION=3.5.2 ; + - CMAKE_VERSION=3.7.2 ; matrix: include: - os: osx @@ -86,11 +86,12 @@ script: - REPO_DIR=$PWD; - mkdir -p $REPO_DIR/build && cd $REPO_DIR/build ; - echo "$CMAKE_PREFIX/bin/cmake .. -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON -DCMAKE_C_COMPILER=$USE_CC -DCMAKE_CXX_COMPILER=$USE_CXX" ; - - $CMAKE_PREFIX/bin/cmake .. -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON -DCMAKE_C_COMPILER=$USE_CC -DCMAKE_CXX_COMPILER=$USE_CXX ; + - $CMAKE_PREFIX/bin/cmake .. -DCMAKE_BUILD_TYPE=Release -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON -DCMAKE_C_COMPILER=$USE_CC -DCMAKE_CXX_COMPILER=$USE_CXX ; - make -j4 after_success: - - test/coroutine_test + - cd $REPO_DIR/build ; + - make make unit_test benchmark ; cache: apt: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 165e9d8..b9ec684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,11 @@ configure_file( add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src") if(PROJECT_ENABLE_SAMPLE) + add_custom_target(benchmark) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/sample") endif() if(PROJECT_ENABLE_UNITTEST) + add_custom_target(unit_test) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/test") -endif() \ No newline at end of file +endif() diff --git a/LICENSE b/LICENSE index 8bb9830..19a94ff 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2016 OWenT +Copyright (c) 2017 OWenT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 877393a..b0ad95a 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ libcopp ======= -> cross-platform coroutine library of c++ +> cross-platform coroutine library in c++ > > in developing ... > > Build & Run Unit Test in | Linux+OSX(Clang+GCC) | Windows(VC+MinGW) | > -------------------------|-----------------------|-------------| > Status | [![Build Status](https://travis-ci.org/owt5008137/libcopp.svg?branch=master)](https://travis-ci.org/owt5008137/libcopp) | [![Build status](https://ci.appveyor.com/api/projects/status/7w6dfnpeahfmgaqj?svg=true)](https://ci.appveyor.com/project/owt5008137/libcopp) | -> Compilers | linux-gcc-4.4
linux-gcc-4.6
linux-gcc-4.9
linux-gcc-6
linux-clang-3.5
osx-apple-clang-6.0
| MSVC 12(Visual Studio 2013)
MSVC 14(Visual Studio 2015)
Mingw64-gcc +> Compilers | linux-gcc-4.4
linux-gcc-4.6
linux-gcc-4.9
linux-gcc-6
linux-clang-3.5
osx-apple-clang-6.0
| MSVC 12(Visual Studio 2013)
MSVC 14(Visual Studio 2015)
MinGW64-gcc > @@ -28,6 +28,7 @@ Generate document with doxygen. Doxygen file located at *doc/libcopp.doxyfile* . + INSTALL ======= @@ -78,14 +79,19 @@ Build **4. run test** *[optional]* - test/coroutine_test + make unit_test + +**5. run benchmark** *[optional]* -**5. install** *[optional]* + make benchmark + +**6. install** *[optional]* make install > Or you can just copy include directory and libcopp.a in lib or lib64 into your project to use it. + USAGE ===== @@ -163,20 +169,20 @@ typedef cotask::task<> my_task_t; int main(int argc, char* argv[]) { // create a task using factory function [with lambda expression] - my_task_t::prt_t task = my_task_t::create([](){ - std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " started"<< std::endl; + my_task_t::prt_t task = my_task_t::create([](){ + std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " started"<< std::endl; cotask::this_task::get_task()->yield(); - std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " resumed"<< std::endl; - return 0; + std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " resumed"<< std::endl; + return 0; }); - - std::cout<< "task "<< task->get_id()<< " created"<< std::endl; + + std::cout<< "task "<< task->get_id()<< " created"<< std::endl; // start a task task->start(); - std::cout<< "task "<< task->get_id()<< " yield"<< std::endl; - task->resume(); - std::cout<< "task "<< task->get_id()<< " stoped, ready to be destroyed."<< std::endl; + std::cout<< "task "<< task->get_id()<< " yield"<< std::endl; + task->resume(); + std::cout<< "task "<< task->get_id()<< " stoped, ready to be destroyed."<< std::endl; return 0; } @@ -226,9 +232,12 @@ HISTORY ------ v0.1.0 +CONSTRIBUTORS +====== ++ [owent](https://github.com/owt5008137) THANKS TO -======== +====== -[mutouyun](https://github.com/mutouyun) ++ [mutouyun](https://github.com/mutouyun) diff --git a/appveyor.yml b/appveyor.yml index 25a62ef..246966d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,7 +26,7 @@ environment: - os: MinGW CMAKE_GEN: MinGW64 -configuration: RelWithDebInfo +configuration: Release # # Cache Cygwin files to speed up build @@ -130,7 +130,7 @@ build_script: if ( "$Env:CMAKE_GEN" -ieq "MinGW32" ) { - echo "$Env:MSYS2_PREFIX/msys2_shell -mingw32 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; mkdir build cmake .. -G 'MSYS Makefiles' -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON ; make -j4" + echo "$Env:MSYS2_PREFIX/msys2_shell -mingw32 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; mkdir build cmake .. -G 'MSYS Makefiles' -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON -DCMAKE_BUILD_TYPE=$Env:CONFIGURATION ; make -j4" & "$Env:MSYS2_PREFIX/msys2_shell" -mingw32 -lc "cd '$Env:APPVEYOR_BUILD_FOLDER/build'; cmake .. -G 'MSYS Makefiles' -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON > '$Env:MSYS2_LOG_FILE' 2>&1; make -j4 >> '$Env:MSYS2_LOG_FILE' 2>&1" | Out-Host @@ -138,7 +138,7 @@ build_script: } else { - echo "$Env:MSYS2_PREFIX/msys2_shell -mingw64 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; cmake .. -G 'MSYS Makefiles' -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON ; make -j4" + echo "$Env:MSYS2_PREFIX/msys2_shell -mingw64 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; cmake .. -G 'MSYS Makefiles' -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON -DCMAKE_BUILD_TYPE=$Env:CONFIGURATION ; make -j4" & "$Env:MSYS2_PREFIX/msys2_shell" -mingw64 -lc "cd '$Env:APPVEYOR_BUILD_FOLDER/build'; cmake .. -G 'MSYS Makefiles' -DPROJECT_ENABLE_UNITTEST=ON -DPROJECT_ENABLE_SAMPLE=ON > '$Env:MSYS2_LOG_FILE' 2>&1; make -j4 >> '$Env:MSYS2_LOG_FILE' 2>&1" | Out-Host @@ -176,17 +176,17 @@ test_script: if ( "$Env:CMAKE_GEN" -ieq "MinGW32" ) { - echo "$Env:MSYS2_PREFIX/msys2_shell -mingw32 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; ./test/coroutine_test.exe;" + echo "$Env:MSYS2_PREFIX/msys2_shell -mingw32 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; make unit_test benchmark;" - & "$Env:MSYS2_PREFIX/msys2_shell" -mingw32 -lc "cd '$Env:APPVEYOR_BUILD_FOLDER/build'; ./test/coroutine_test.exe > '$Env:MSYS2_LOG_FILE';" | Out-Host + & "$Env:MSYS2_PREFIX/msys2_shell" -mingw32 -lc "cd '$Env:APPVEYOR_BUILD_FOLDER/build'; make unit_test benchmark > '$Env:MSYS2_LOG_FILE';" | Out-Host Get-Content "$Env:MSYS2_LOG_FILE" } else { - echo "$Env:MSYS2_PREFIX/msys2_shell -mingw64 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; ./test/coroutine_test.exe;" + echo "$Env:MSYS2_PREFIX/msys2_shell -mingw64 -lc cd '$Env:APPVEYOR_BUILD_FOLDER/build'; make unit_test benchmark;" - & "$Env:MSYS2_PREFIX/msys2_shell" -mingw64 -lc "cd '$Env:APPVEYOR_BUILD_FOLDER/build'; ./test/coroutine_test.exe > '$Env:MSYS2_LOG_FILE';" | Out-Host + & "$Env:MSYS2_PREFIX/msys2_shell" -mingw64 -lc "cd '$Env:APPVEYOR_BUILD_FOLDER/build'; make unit_test benchmark > '$Env:MSYS2_LOG_FILE';" | Out-Host Get-Content "$Env:MSYS2_LOG_FILE" @@ -196,6 +196,8 @@ test_script: & "test/$Env:CONFIGURATION/coroutine_test.exe" + & "../doc/reports/windows_start_benchmark.bat" + } # diff --git a/doc/md/000_DESCRIPTION.md b/doc/md/000_DESCRIPTION.md index b76cc10..029e2e3 100644 --- a/doc/md/000_DESCRIPTION.md +++ b/doc/md/000_DESCRIPTION.md @@ -1,13 +1,31 @@ libcopp ======= -> cross-platform coroutine library of c++ -> + +> cross-platform coroutine library in c++ +> > in developing ... +> +> Build & Run Unit Test in | Linux+OSX(Clang+GCC) | Windows(VC+MinGW) | +> -------------------------|-----------------------|-------------| +> Status | [![Build Status](https://travis-ci.org/owt5008137/libcopp.svg?branch=master)](https://travis-ci.org/owt5008137/libcopp) | [![Build status](https://ci.appveyor.com/api/projects/status/7w6dfnpeahfmgaqj?svg=true)](https://ci.appveyor.com/project/owt5008137/libcopp) | +> Compilers | linux-gcc-4.4
linux-gcc-4.6
linux-gcc-4.9
linux-gcc-6
linux-clang-3.5
osx-apple-clang-6.0
| MSVC 12(Visual Studio 2013)
MSVC 14(Visual Studio 2015)
MinGW64-gcc +> + + +Gitter +------ +[![Gitter](https://badges.gitter.im/owt5008137/libcopp.svg)](https://gitter.im/owt5008137/libcopp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +LICENSE +------- -## LICENSE License under the MIT license -## Document +Document +-------- + Generate document with doxygen. Doxygen file located at *doc/libcopp.doxyfile* . + + diff --git a/doc/md/010_INSTALL.md b/doc/md/010_INSTALL.md index 22543db..ac27cd7 100644 --- a/doc/md/010_INSTALL.md +++ b/doc/md/010_INSTALL.md @@ -1,37 +1,46 @@ -# INSTALL +INSTALL +======= > libcopp use cmake to generate makefile and switch build tools. -## Prerequisites -+ **[required]** GCC or Clang or VC support ISO C++ 98 and upper -+ **[required]** [cmake](www.cmake.org) 2.8.9 and upper -+ **[optional]** [gtest](https://code.google.com/p/googletest/) 1.6.0 and upper (better test supported) +Prerequisites +------------- -### Unix -* **[required]** ar, as, ld ([binutils](http://www.gnu.org/software/binutils/)) -* **[optional]** if using [gtest](https://code.google.com/p/googletest/), pthread is required. +- **[required]** GCC or Clang or VC support ISO C++ 03 and upper +- **[required]** [cmake](www.cmake.org) 3.1.0 and upper +- **[optional]** [gtest](https://code.google.com/p/googletest/) 1.6.0 and upper (better test supported) +- **[optional]** [Boost.Test](http://www.boost.org/doc/libs/release/libs/test/) (Boost.Test supported) + +### Unix + +- **[required]** ar, as, ld ([binutils](http://www.gnu.org/software/binutils/)) +- **[optional]** if using [gtest](https://code.google.com/p/googletest/), pthread is required. ### Windows -* **[required]** masm (in vc) -* **[optional]** if using [gtest](https://code.google.com/p/googletest/), pthread is required. +- **[required]** masm (in vc) +- **[optional]** if using [gtest](https://code.google.com/p/googletest/), pthread is required. + +Build +----- -## Build **1. make a build directory** mkdir build - + **2. run cmake command** cmake [options] -> options can be cmake options. such as set compile toolchains, source directory or options of libcopp that control build actions. -> libcopp options are listed below: ->> -DBUILD_SHARED_LIBS=YES|NO [default=NO] enable build dynamic library. +> options can be cmake options. such as set compile toolchains, source directory or options of libcopp that control build actions. libcopp options are listed below: + +> > -DBUILD\_SHARED\_LIBS=YES|NO [default=NO] enable build dynamic library. ->> -DLIBCOPP_ENABLE_SEGMENTED_STACKS=YES|NO [default=NO] enable split stack supported context.(it's only availabe in linux and gcc 4.7.0 or upper) +> > -DLIBCOPP\_ENABLE\_SEGMENTED\_STACKS=YES|NO [default=NO] enable split stack supported context.(it's only availabe in linux and gcc 4.7.0 or upper) ->> -DGTEST_ROOT=[path] set gtest library install prefix path +> > -DLIBCOPP\_ENABLE\_VALGRIND=YES|NO [default=YES] enable valgrind supported context. + +> > -DGTEST\_ROOT=[path] set gtest library install prefix path **3. make libcopp** @@ -39,10 +48,16 @@ **4. run test** *[optional]* - test/coroutine_test + make unit_test + +**5. run benchmark** *[optional]* + + make benchmark -**5. install** *[optional]* +**6. install** *[optional]* make install > Or you can just copy include directory and libcopp.a in lib or lib64 into your project to use it. + + diff --git a/doc/md/020_USAGE.md b/doc/md/020_USAGE.md index 1a140d4..ee62d63 100644 --- a/doc/md/020_USAGE.md +++ b/doc/md/020_USAGE.md @@ -1,8 +1,11 @@ -# USAGE +USAGE +===== > Just include headers and linking library file of your platform to use libcopp -## Example +Example +------- + ### coroutine_context example There is a simple example of using coroutine context below: @@ -60,7 +63,7 @@ And then, you can custom many function such as set your stack allocator, corouti ### coroutine task example -There is also a simple example of using coroutine task below: +There is a simple example of using coroutine task below: ``` {.cpp} #include @@ -72,22 +75,24 @@ typedef cotask::task<> my_task_t; int main(int argc, char* argv[]) { // create a task using factory function [with lambda expression] - my_task_t::prt_t task = my_task_t::create([](){ - std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " started"<< std::endl; + my_task_t::prt_t task = my_task_t::create([](){ + std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " started"<< std::endl; cotask::this_task::get_task()->yield(); - std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " resumed"<< std::endl; - return 0; + std::cout<< "task "<< cotask::this_task::get_task()->get_id()<< " resumed"<< std::endl; + return 0; }); - - std::cout<< "task "<< task->get_id()<< " created"<< std::endl; + + std::cout<< "task "<< task->get_id()<< " created"<< std::endl; // start a task task->start(); - std::cout<< "task "<< task->get_id()<< " yield"<< std::endl; - task->resume(); - std::cout<< "task "<< task->get_id()<< " stoped, ready to be destroyed."<< std::endl; + std::cout<< "task "<< task->get_id()<< " yield"<< std::endl; + task->resume(); + std::cout<< "task "<< task->get_id()<< " stoped, ready to be destroyed."<< std::endl; return 0; } ``` And then, you can custom many functions by set your macro type of coroutine and task to do some other function. + + diff --git a/doc/md/050_NOTICE.md b/doc/md/050_NOTICE.md index d1623e8..0129c70 100644 --- a/doc/md/050_NOTICE.md +++ b/doc/md/050_NOTICE.md @@ -1,4 +1,5 @@ -# NOTICE -split stack support: if in Linux and user gcc 4.7.0 or upper, add -DLIBCOPP_ENABLE_SEGMENTED_STACKS=YES to use split stack supported context. +NOTICE +====== +split stack support: if in Linux and user gcc 4.7.0 or upper, add -DLIBCOPP\_ENABLE\_SEGMENTED\_STACKS=YES to use split stack supported context. diff --git a/doc/md/060_DEVELOPER.md b/doc/md/060_DEVELOPER.md index 198c8df..c13e448 100644 --- a/doc/md/060_DEVELOPER.md +++ b/doc/md/060_DEVELOPER.md @@ -1,8 +1,7 @@ -# DEVELOPER +DEVELOPER +========= [basic coroutine object summary](doc/basic_coroutine_class.txt) [safe coroutine object summary](doc/safe_basic_coroutine_class.txt) - - diff --git a/doc/md/070_HISTORY.md b/doc/md/070_HISTORY.md new file mode 100644 index 0000000..3a4934e --- /dev/null +++ b/doc/md/070_HISTORY.md @@ -0,0 +1,30 @@ +HISTORY +======== +2016-06-16 +------ +1. [BOOST] merge boost.context 1.61.0 and use the new jump progress(see https://owent.net/90QQw for detail) +2. [BOOST] enable valgrind support if valgrind/valgrind.h exists +3. [CXX] use cmake to detect the function of compiler +4. [OPTIMIZE] using pthread key when c++11 TLS not available +5. [OPTIMIZE] remove coroutine_context_safe_base.coroutine_context_base is also thread safe now +6. [OPTIMIZE] remove all global variables of cotask +7. [OPTIMIZE] remove std/thread.h, add noexpect if available +8. [CI] CI use build matrix to test more compiler +9. [BUILD] use RelWithDebInfo for default + +2016-02-27 +------ +1. v0.2.0, this version is used in our server for about one year. + +2015-12-29 +------ +1. add support for valgrind +2. add ci configure +3. merge boost.context 1.60.0 +4. add -fPIC, fix spin lock +5. some environment do not support TLS, make these environment can compile success + +2014-07-25 +------ +v0.1.0 + diff --git a/doc/md/080_CONSTRIBUTOR.md b/doc/md/080_CONSTRIBUTOR.md new file mode 100644 index 0000000..7151a68 --- /dev/null +++ b/doc/md/080_CONSTRIBUTOR.md @@ -0,0 +1,9 @@ +CONSTRIBUTORS +====== ++ [owent](https://github.com/owt5008137) + +THANKS TO +====== + ++ [mutouyun](https://github.com/mutouyun) + diff --git a/doc/md/080_SCHEDUAL.md b/doc/md/080_SCHEDUAL.md deleted file mode 100644 index 98f74aa..0000000 --- a/doc/md/080_SCHEDUAL.md +++ /dev/null @@ -1,7 +0,0 @@ -# SCHEDUAL - -[task schedual](doc/task_schedual.txt) - - - - diff --git a/doc/reports/linux_start_benchmark.sh b/doc/reports/linux_start_benchmark.sh index 88346f8..d225d47 100755 --- a/doc/reports/linux_start_benchmark.sh +++ b/doc/reports/linux_start_benchmark.sh @@ -5,50 +5,27 @@ if [ $# -lt 2 ]; then exit -1; fi -echo "###################### context coroutine (stack using memory pool) ###################" >> "$2"; -echo "########## Cmd: sample/sample_benchmark_coroutine_mem_pool 10000 1000 200" >> "$2"; "$1"/sample/sample_benchmark_coroutine_mem_pool 10000 1000 200 >> "$2"; -echo "########## Cmd: sample/sample_benchmark_coroutines_mem_pool 1000 1000 2048" >> "$2"; "$1"/sample/sample_benchmark_coroutine_mem_pool 1000 1000 2048 >> "$2"; echo "" >> "$2"; - -echo "###################### context coroutine (stack using default allocator[mmap]) ###################" >> "$2"; -echo "########## Cmd: sample/sample_benchmark_coroutine 10000 1000 200" >> "$2"; "$1"/sample/sample_benchmark_coroutine 10000 1000 200 >> "$2"; -echo "########## Cmd: sample/sample_benchmark_coroutine 1000 1000 2048" >> "$2"; "$1"/sample/sample_benchmark_coroutine 1000 1000 2048 >> "$2"; echo "" >> "$2"; - -echo "###################### context coroutine (stack using malloc/free [ptmalloc]) ###################" >> "$2"; -echo "########## Cmd: sample/sample_benchmark_coroutine_malloc 10000 1000 200" >> "$2"; "$1"/sample/sample_benchmark_coroutine_malloc 10000 1000 200 >> "$2"; -echo "########## Cmd: sample/sample_benchmark_coroutine_malloc 1000 1000 2048" >> "$2"; "$1"/sample/sample_benchmark_coroutine_malloc 1000 1000 2048 >> "$2"; echo "" >> "$2"; - -echo "###################### task (stack using memory pool) ###################" >> "$2"; -echo "########## Cmd: sample/sample_benchmark_task_mem_pool 10000 1000 200" >> "$2"; "$1"/sample/sample_benchmark_task_mem_pool 10000 1000 200 >> "$2"; -echo "########## Cmd: sample/sample_benchmark_task_mem_pool 1000 1000 2048" >> "$2"; "$1"/sample/sample_benchmark_task_mem_pool 1000 1000 2048 >> "$2"; echo "" >> "$2"; - -echo "###################### task (stack using default allocator[mmap]) ###################" >> "$2"; -echo "########## Cmd: sample/sample_benchmark_task 10000 1000 200" >> "$2"; "$1"/sample/sample_benchmark_task 10000 1000 200 >> "$2"; -echo "########## Cmd: sample/sample_benchmark_task 1000 1000 2048" >> "$2"; "$1"/sample/sample_benchmark_task 1000 1000 2048 >> "$2"; echo "" >> "$2"; - -echo "###################### task (stack using malloc/free [ptmalloc]) ###################" >> "$2"; -echo "########## Cmd: sample/sample_benchmark_task_malloc 10000 1000 200" >> "$2"; "$1"/sample/sample_benchmark_task_malloc 10000 1000 200 >> "$2"; -echo "########## Cmd: sample/sample_benchmark_task_malloc 1000 1000 2048" >> "$2"; "$1"/sample/sample_benchmark_task_malloc 1000 1000 2048 >> "$2"; echo "" >> "$2"; diff --git a/doc/reports/windows_start_benchmark.bat b/doc/reports/windows_start_benchmark.bat index 7b5bb44..f9a8ffd 100644 --- a/doc/reports/windows_start_benchmark.bat +++ b/doc/reports/windows_start_benchmark.bat @@ -1,51 +1,26 @@ @echo off -echo ###################### context coroutine (stack using memory pool) ################### >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_coroutine_mem_pool.exe 10000 1000 200 >> "%2" "%1/sample/Release/sample_benchmark_coroutine_mem_pool.exe" 10000 1000 200 >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_coroutine_mem_pool.exe 1000 1000 2048 >> "%2" "%1/sample/Release/sample_benchmark_coroutine_mem_pool.exe" 1000 1000 2048 >> "%2" echo\ >> "%2" - -echo ###################### context coroutine (stack using default allocator[VirtualAlloc]) ################### >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_coroutine.exe 10000 1000 200 >> "%2" "%1/sample/Release/sample_benchmark_coroutine.exe" 10000 1000 200 >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_coroutine.exe 1000 1000 2048 >> "%2" "%1/sample/Release/sample_benchmark_coroutine.exe" 1000 1000 2048 >> "%2" echo\ >> "%2" - -echo ###################### context coroutine (stack using malloc/free) ################### >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_coroutine_malloc.exe 10000 1000 200 >> "%2" "%1/sample/Release/sample_benchmark_coroutine_malloc.exe" 10000 1000 200 >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_coroutine_malloc.exe 1000 1000 2048 >> "%2" "%1/sample/Release/sample_benchmark_coroutine_malloc.exe" 1000 1000 2048 >> "%2" echo\ >> "%2" - -echo ###################### task (stack using memory pool) ################### >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_task_mem_pool.exe 10000 1000 200 >> "%2" "%1/sample/Release/sample_benchmark_task_mem_pool.exe" 10000 1000 200 >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_task_mem_pool.exe 1000 1000 2048 >> "%2" "%1/sample/Release/sample_benchmark_task_mem_pool.exe" 1000 1000 2048 >> "%2" echo\ >> "%2" - -echo ###################### task (stack using default allocator[VirtualAlloc]) ################### >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_task.exe 10000 1000 200 >> "%2" "%1/sample/Release/sample_benchmark_task.exe" 10000 1000 200 >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_task.exe 1000 1000 2048 >> "%2" "%1/sample/Release/sample_benchmark_task.exe" 1000 1000 2048 >> "%2" echo\ >> "%2" - -echo ###################### task (stack using malloc/free) ################### >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_task_malloc.exe 10000 1000 200 >> "%2" "%1/sample/Release/sample_benchmark_task_malloc.exe" 10000 1000 200 >> "%2" -echo ########## Cmd: sample/Release/sample_benchmark_task_malloc.exe 1000 1000 2048 >> "%2" "%1/sample/Release/sample_benchmark_task_malloc.exe" 1000 1000 2048 >> "%2" echo\ >> "%2" - - diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 8a5bdd6..41275be 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -16,10 +16,25 @@ set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/sample") foreach(SAMPLE_SRC_FILE IN LISTS SAMPLE_SRC_LIST) get_filename_component(SAMPLE_SRC_BIN_NAME "${SAMPLE_SRC_FILE}" NAME_WE) - add_executable("${SAMPLE_SRC_BIN_NAME}" ${SAMPLE_SRC_FILE}) - target_link_libraries("${SAMPLE_SRC_BIN_NAME}" + add_executable(${SAMPLE_SRC_BIN_NAME} ${SAMPLE_SRC_FILE}) + target_link_libraries(${SAMPLE_SRC_BIN_NAME} ${PROJECT_LIBCOTASK_LIB_LINK} ${PROJECT_LIBCOPP_LIB_LINK} ${COMPILER_OPTION_EXTERN_CXX_LIBS} ) + + # add benchmark script + add_custom_target("run_test_${SAMPLE_SRC_BIN_NAME}_10000" + "./${SAMPLE_SRC_BIN_NAME}" 10000 1000 200 + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + ) + add_dependencies(benchmark "run_test_${SAMPLE_SRC_BIN_NAME}_10000") + add_dependencies("run_test_${SAMPLE_SRC_BIN_NAME}_10000" ${SAMPLE_SRC_BIN_NAME}) + + add_custom_target("run_test_${SAMPLE_SRC_BIN_NAME}_1000" + "./${SAMPLE_SRC_BIN_NAME}" 1000 1000 2048 + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} + ) + add_dependencies(benchmark "run_test_${SAMPLE_SRC_BIN_NAME}_1000") + add_dependencies("run_test_${SAMPLE_SRC_BIN_NAME}_1000" ${SAMPLE_SRC_BIN_NAME}) endforeach() diff --git a/sample/sample_benchmark_coroutine.cpp b/sample/sample_benchmark_coroutine.cpp index a96a350..2308925 100644 --- a/sample/sample_benchmark_coroutine.cpp +++ b/sample/sample_benchmark_coroutine.cpp @@ -43,6 +43,19 @@ int max_coroutine_number = 100000; // 协程数量 copp::coroutine_context_default* co_arr = NULL; my_runner* runner = NULL; int main(int argc, char* argv[]) { +#ifdef COPP_MACRO_SYS_POSIX + puts("###################### context coroutine (stack using default allocator[mmap]) ###################"); +#elif defined(COPP_MACRO_SYS_WIN) + puts("###################### context coroutine (stack using default allocator[VirtualAlloc]) ###################"); +#else + puts("###################### context coroutine (stack using default allocator ###################"); +#endif + printf("########## Cmd:"); + for (int i = 0; i < argc; ++ i) { + printf(" %s", argv[i]); + } + puts(""); + if (argc > 1) { max_coroutine_number = atoi(argv[1]); } diff --git a/sample/sample_benchmark_coroutine_malloc.cpp b/sample/sample_benchmark_coroutine_malloc.cpp index b449caa..07b19f5 100644 --- a/sample/sample_benchmark_coroutine_malloc.cpp +++ b/sample/sample_benchmark_coroutine_malloc.cpp @@ -49,6 +49,13 @@ my_cotoutine_t* co_arr = NULL; my_runner* runner = NULL; int main(int argc, char* argv[]) { + puts("###################### context coroutine (stack using malloc/free) ###################"); + printf("########## Cmd:"); + for (int i = 0; i < argc; ++ i) { + printf(" %s", argv[i]); + } + puts(""); + if (argc > 1) { MAX_COROUTINE_NUMBER = atoi(argv[1]); } diff --git a/sample/sample_benchmark_coroutine_mem_pool.cpp b/sample/sample_benchmark_coroutine_mem_pool.cpp index db9d22c..1338f1a 100644 --- a/sample/sample_benchmark_coroutine_mem_pool.cpp +++ b/sample/sample_benchmark_coroutine_mem_pool.cpp @@ -52,6 +52,13 @@ my_runner* runner = NULL; char * stack_mem_pool = NULL; int main(int argc, char* argv[]) { + puts("###################### context coroutine (stack using memory pool) ###################"); + printf("########## Cmd:"); + for (int i = 0; i < argc; ++ i) { + printf(" %s", argv[i]); + } + puts(""); + if (argc > 1) { MAX_COROUTINE_NUMBER = atoi(argv[1]); } diff --git a/sample/sample_benchmark_task.cpp b/sample/sample_benchmark_task.cpp index 99e260f..8d2c131 100644 --- a/sample/sample_benchmark_task.cpp +++ b/sample/sample_benchmark_task.cpp @@ -42,6 +42,19 @@ int my_task_action() { } int main(int argc, char* argv[]) { +#ifdef COPP_MACRO_SYS_POSIX + puts("###################### context coroutine (stack using default allocator[mmap]) ###################"); +#elif defined(COPP_MACRO_SYS_WIN) + puts("###################### context coroutine (stack using default allocator[VirtualAlloc]) ###################"); +#else + puts("###################### context coroutine (stack using default allocator ###################"); +#endif + printf("########## Cmd:"); + for (int i = 0; i < argc; ++ i) { + printf(" %s", argv[i]); + } + puts(""); + if (argc > 1) { max_task_number = atoi(argv[1]); } diff --git a/sample/sample_benchmark_task_malloc.cpp b/sample/sample_benchmark_task_malloc.cpp index 2cc09d8..137ec72 100644 --- a/sample/sample_benchmark_task_malloc.cpp +++ b/sample/sample_benchmark_task_malloc.cpp @@ -52,6 +52,13 @@ int my_task_action() { } int main(int argc, char* argv[]) { + puts("###################### task (stack using malloc/free) ###################"); + printf("########## Cmd:"); + for (int i = 0; i < argc; ++ i) { + printf(" %s", argv[i]); + } + puts(""); + if (argc > 1) { max_task_number = atoi(argv[1]); } diff --git a/sample/sample_benchmark_task_mem_pool.cpp b/sample/sample_benchmark_task_mem_pool.cpp index 8bc9b32..ad93ed7 100644 --- a/sample/sample_benchmark_task_mem_pool.cpp +++ b/sample/sample_benchmark_task_mem_pool.cpp @@ -102,6 +102,13 @@ int my_task_action() { } int main(int argc, char* argv[]) { + puts("###################### task (stack using memory pool) ###################"); + printf("########## Cmd:"); + for (int i = 0; i < argc; ++ i) { + printf(" %s", argv[i]); + } + puts(""); + if (argc > 1) { max_task_number = atoi(argv[1]); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4619662..eca7023 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,6 @@ EchoWithColor(COLOR GREEN "-- Configure Test Projects") -enable_testing() find_package(GTest) set (PROJECT_LIBCOPP_TEST_LIB_LINK "") @@ -73,4 +72,9 @@ target_link_libraries(coroutine_test ${COMPILER_OPTION_EXTERN_CXX_LIBS} ) -add_test(test coroutine_test) +add_custom_target(run_test_coroutine_test + ./coroutine_test + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} +) +add_dependencies(unit_test run_test_coroutine_test) +add_dependencies(run_test_coroutine_test coroutine_test)