Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change #1542

Closed
wants to merge 3 commits into from
Closed

Change #1542

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/common/thread/test/ThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gtest/gtest.h>
#include "thread/NamedThread.h"

#include "vector"
namespace nebula {
namespace thread {

Expand All @@ -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 <std::thread>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
Binary file added src/common/time/test/.DurationTest.cpp.swl
Binary file not shown.
Binary file added src/common/time/test/.DurationTest.cpp.swm
Binary file not shown.
Binary file added src/common/time/test/.DurationTest.cpp.swn
Binary file not shown.
Binary file added src/common/time/test/.DurationTest.cpp.swo
Binary file not shown.
18 changes: 18 additions & 0 deletions src/common/time/test/.exrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if &cp | set nocp | endif
let s:cpo_save=&cpo
set cpo&vim
vmap gx <Plug>NetrwBrowseXVis
nmap gx <Plug>NetrwBrowseX
vnoremap <silent> <Plug>NetrwBrowseXVis :call netrw#BrowseXVis()
nnoremap <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),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 :
8 changes: 8 additions & 0 deletions src/common/time/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ nebula_add_test(
gtest
)








nebula_add_test(
NAME
wallclock_test
Expand All @@ -26,6 +33,7 @@ nebula_add_test(
nebula_add_executable(
NAME
duration_bm

SOURCES
DurationBenchmark.cpp
OBJECTS
Expand Down
29 changes: 28 additions & 1 deletion src/common/time/test/DurationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#include "base/Base.h"
#include <gtest/gtest.h>
#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;
Expand Down Expand Up @@ -40,7 +43,31 @@ TEST(Duration, elapsedInMilliSeconds) {
dur.elapsedInMSec()) << "Inaccuracy in iteration " << i;
}
}
TEST(WallClock , time ) {
std::vector<int64_t> time1;
std::vector<int64_t> 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 " <<std::endl;

for (int i = 0; i < 10 ; i++) {
int64_t a = (time1[i]-average)*(time1[i]-average);
time2.push_back(a);
}
int64_t sum2 = std::accumulate(time2.begin(), time2.end(), 0);
double variance = sum2*1.0/9;
std::cout << "The Variance Is : "<< variance << std::endl;
double error = (abs(average-3000) * 1.0 / 3000) * 100;
std :: cout << "Test Error Is : " << error << "%" << std::endl;
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
Expand Down
1 change: 1 addition & 0 deletions src/common/time/test/duration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// copyright <2018> djasioaw