Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assert execution time in Google Test?

I am using Google's C++ testing framework Gtest. I would like to test a function against its execution time, e.g. function foo() fails if its execution is longer than 3ms. I could not find an ASSERT statement to achieve this. Does gtest not include such a feature ?

like image 890
user1304680 Avatar asked Oct 02 '13 11:10

user1304680


2 Answers

Why not to use such simple solution?

//pseudo code
clock_t t = clock();
foo();
const double work_time = (clock() - t) / double(CLOCKS_PER_SEC);
ASSERT_TRUE(work_time <= 0.003);
like image 131
fghj Avatar answered Sep 28 '22 07:09

fghj


Probably doesn't exist as the bug is still open: http://code.google.com/p/googletest/issues/detail?id=348

like image 37
Hei Avatar answered Sep 28 '22 07:09

Hei