mirror of
https://github.com/catchorg/Catch2.git
synced 2025-06-01 01:18:02 +00:00
Split SelfTest test files into Usage and Introspective varieties
Usage: just exercises Catch. The tests are over arbitrary date/ types Introspective: Tests parts of Catch itself.
This commit is contained in:
parent
55b71bebf1
commit
e34754e433
29 changed files with 1451 additions and 1446 deletions
43
projects/SelfTest/UsageTests/Benchmark.tests.cpp
Normal file
43
projects/SelfTest/UsageTests/Benchmark.tests.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "catch.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
TEST_CASE( "benchmarked", "[!benchmark]" ) {
|
||||
|
||||
static const int size = 100;
|
||||
|
||||
std::vector<int> v;
|
||||
std::map<int, int> m;
|
||||
|
||||
BENCHMARK( "Load up a vector" ) {
|
||||
v = std::vector<int>();
|
||||
for(int i =0; i < size; ++i )
|
||||
v.push_back( i );
|
||||
}
|
||||
REQUIRE( v.size() == size );
|
||||
|
||||
BENCHMARK( "Load up a map" ) {
|
||||
m = std::map<int, int>();
|
||||
for(int i =0; i < size; ++i )
|
||||
m.insert( { i, i+1 } );
|
||||
}
|
||||
REQUIRE( m.size() == size );
|
||||
|
||||
BENCHMARK( "Reserved vector" ) {
|
||||
v = std::vector<int>();
|
||||
v.reserve(size);
|
||||
for(int i =0; i < size; ++i )
|
||||
v.push_back( i );
|
||||
}
|
||||
REQUIRE( v.size() == size );
|
||||
|
||||
int array[size];
|
||||
BENCHMARK( "A fixed size array that should require no allocations" ) {
|
||||
for(int i =0; i < size; ++i )
|
||||
array[i] = i;
|
||||
}
|
||||
int sum = 0;
|
||||
for(int i =0; i < size; ++i )
|
||||
sum += array[i];
|
||||
REQUIRE( sum > size );
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue