diff --git a/src/common/thread/test/ThreadTest.cpp b/src/common/thread/test/ThreadTest.cpp index ae3cc65f871..02564cf477e 100644 --- a/src/common/thread/test/ThreadTest.cpp +++ b/src/common/thread/test/ThreadTest.cpp @@ -3,11 +3,11 @@ * This source code is licensed under Apache 2.0 License, * attached with Common Clause Condition 1.0, found in the LICENSES directory. */ - +#include "iostream" #include "base/Base.h" #include #include "thread/NamedThread.h" - +#include "vector" namespace nebula { namespace thread { @@ -25,6 +25,18 @@ TEST(NamedThread, ThreadName) { TEST(NamedThread, ThreadID) { ASSERT_EQ(::getpid(), nebula::thread::gettid()); } +TEST(NameThread, test) { + static int j = 0; + std::vector t; + for (int i = 0; i < 10; i++) { + std::thread mythread(j++); + t.push_back(std::move(mythread)); + } + for (int i = 0; i < 10 ; i++) { + t[i].join(); +} + ASSERT_GE(j, 10); +} } // namespace thread } // namespace nebula diff --git a/src/common/time/test/.DurationTest.cpp.swl b/src/common/time/test/.DurationTest.cpp.swl new file mode 100644 index 00000000000..93821fab8a5 Binary files /dev/null and b/src/common/time/test/.DurationTest.cpp.swl differ diff --git a/src/common/time/test/.DurationTest.cpp.swm b/src/common/time/test/.DurationTest.cpp.swm new file mode 100644 index 00000000000..47456164d19 Binary files /dev/null and b/src/common/time/test/.DurationTest.cpp.swm differ diff --git a/src/common/time/test/.DurationTest.cpp.swn b/src/common/time/test/.DurationTest.cpp.swn new file mode 100644 index 00000000000..92aa1fe6a6a Binary files /dev/null and b/src/common/time/test/.DurationTest.cpp.swn differ diff --git a/src/common/time/test/.DurationTest.cpp.swo b/src/common/time/test/.DurationTest.cpp.swo new file mode 100644 index 00000000000..368f96c6b4b Binary files /dev/null and b/src/common/time/test/.DurationTest.cpp.swo differ diff --git a/src/common/time/test/.exrc b/src/common/time/test/.exrc new file mode 100644 index 00000000000..e4200768bd3 --- /dev/null +++ b/src/common/time/test/.exrc @@ -0,0 +1,18 @@ +if &cp | set nocp | endif +let s:cpo_save=&cpo +set cpo&vim +vmap gx NetrwBrowseXVis +nmap gx NetrwBrowseX +vnoremap NetrwBrowseXVis :call netrw#BrowseXVis() +nnoremap NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '')),netrw#CheckIfRemote()) +let &cpo=s:cpo_save +unlet s:cpo_save +set ambiwidth=double +set backspace=indent,eol,start +set fileencodings=ucs-bom,utf-8,default,latin1 +set helplang=en +set nomodeline +set ruler +set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after +set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc +" vim: set ft=vim : diff --git a/src/common/time/test/CMakeLists.txt b/src/common/time/test/CMakeLists.txt index 1b73d25d3c8..a2d1d7c9182 100644 --- a/src/common/time/test/CMakeLists.txt +++ b/src/common/time/test/CMakeLists.txt @@ -11,6 +11,13 @@ nebula_add_test( gtest ) + + + + + + + nebula_add_test( NAME wallclock_test @@ -26,6 +33,7 @@ nebula_add_test( nebula_add_executable( NAME duration_bm + SOURCES DurationBenchmark.cpp OBJECTS diff --git a/src/common/time/test/DurationTest.cpp b/src/common/time/test/DurationTest.cpp index 1c7e2dd142e..1869d7b17d4 100644 --- a/src/common/time/test/DurationTest.cpp +++ b/src/common/time/test/DurationTest.cpp @@ -7,9 +7,12 @@ #include "base/Base.h" #include #include "time/Duration.h" +#include "vector" +#include "cmath" +#include "time/WallClock.h" using nebula::time::Duration; - +using nebula::time::WallClock; TEST(Duration, elapsedInSeconds) { for (int i = 0; i < 5; i++) { Duration dur; @@ -40,7 +43,31 @@ TEST(Duration, elapsedInMilliSeconds) { dur.elapsedInMSec()) << "Inaccuracy in iteration " << i; } } +TEST(WallClock , time ) { + std::vector time1; + std::vector time2; + for (uint32_t i = 0; i < 10; i++) { + auto sec1 = WallClock::fastNowInMicroSec(); + usleep(3000); + auto sec2 = WallClock::fastNowInMicroSec(); + auto cost_time = sec2-sec1; + time1.push_back(cost_time); + } + std::cout << time1[0] << std::endl; + int64_t sum = std::accumulate(time1.begin(), time1.end(), 0); + double average = sum*1.0/10; + std::cout << "Mean Error : " << average-3000 << "ms " < djasioaw