Skip to content

Commit

Permalink
tests: sc_time/test19: simple benchmark mode
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp A. Hartmann <[email protected]>
  • Loading branch information
pah committed Nov 22, 2024
1 parent 63d1f3d commit dfbd5fb
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/systemc/kernel/sc_time/test19/test19.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ void check_time( const sc_time& t, sc_time_unit tu, const std::string & str )
{
sc_time_tuple tp = t;

#ifndef BENCHMARK
std::cout << t.to_string() << ", value=" << t.value() << std::endl;
std::cout << " ";
if( tp.has_value() )
std::cout << "t.value=" << tp.value();
else
std::cout << "t.double=" << tp.to_double();
std::cout << ", t.unit=" << tp.unit_symbol()
<< std::endl;
std::cout << ", t.unit=" << tp.unit_symbol() << std::endl;
#endif // BENCHMARK

sc_assert( tp.has_value() );
sc_assert( t.to_string() == str );
Expand All @@ -50,10 +51,26 @@ void check_time( const sc_time& t, sc_time_unit tu, const std::string & str )
sc_assert( t == u );
sc_assert( u == tp );
sc_assert( tp.unit() == sc_time_tuple(u).unit() );
}

#ifdef BENCHMARK
int test_iteration();

int sc_main( int, char*[] )
{
sc_report_handler::set_actions( SC_WARNING, SC_DO_NOTHING );

static const int iterations = 20'000;
for(int i = 0; i < iterations; ++i ) {
test_iteration();
}
return 0;
}

int test_iteration()
#else
int sc_main( int, char*[] )
#endif
{
sc_report_handler::set_actions( SC_ID_SET_TIME_RESOLUTION_, SC_DO_NOTHING );
sc_report_handler::set_actions( SC_ID_TIME_CONVERSION_FAILED_, SC_DISPLAY );
Expand All @@ -77,7 +94,9 @@ int sc_main( int, char*[] )
for( auto res : resolutions )
{
sc_set_time_resolution( res, resunit );
#ifndef BENCHMARK
std::cout << "\nResolution = " << sc_get_time_resolution() << std::endl;
#endif // BENCHMARK

check_time( sc_time( 10, SC_NS), SC_NS, "10 ns" );
check_time( sc_time( 100, SC_NS), SC_NS, "100 ns" );
Expand All @@ -98,12 +117,16 @@ int sc_main( int, char*[] )

{
sc_set_time_resolution(1, SC_SEC);
#ifndef BENCHMARK
std::cout << "\nResolution = " << sc_get_time_resolution() << std::endl;
#endif // BENCHMARK

auto t = sc_core::sc_time(1, SC_SEC);
check_time( t, SC_SEC, "1 s");
}

#ifndef BENCHMARK
cout << "\nProgram completed" << endl;
#endif // BENCHMARK
return 0;
}

0 comments on commit dfbd5fb

Please sign in to comment.