Skip to content

Commit

Permalink
add stumpless_element_to_string benchmark (#396)
Browse files Browse the repository at this point in the history
Add a benchmark test for stumpless_element_to_string.

This fixes #375, which can be referenced for more information.
  • Loading branch information
Miroslav263 authored Dec 20, 2023
1 parent cbfe354 commit 6122a79
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/performance/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ NEW_MEMORY_COUNTER( copy_element )
NEW_MEMORY_COUNTER( load_element )
NEW_MEMORY_COUNTER( new_element )
NEW_MEMORY_COUNTER( set_element_name )
NEW_MEMORY_COUNTER( element_to_string )

static void CopyElement(benchmark::State& state){
struct stumpless_element *element;
Expand Down Expand Up @@ -113,7 +114,32 @@ static void SetElementName(benchmark::State& state){
SET_STATE_COUNTERS( state, set_element_name );
}

static void ElementToString(benchmark::State& state){
struct stumpless_element *element;
const char *result;

INIT_MEMORY_COUNTER( element_to_string );

element = stumpless_new_element( "new-element-name" );

for(auto _ : state){
result = stumpless_element_to_string( element );
if( !result ) {
state.SkipWithError( "could not convert the element to string" );
}
else {
element_to_string_memory_counter_free( ( void * ) result );
}
}

stumpless_destroy_element_and_contents( element );
stumpless_free_all( );

SET_STATE_COUNTERS( state, element_to_string );
}

BENCHMARK( CopyElement );
BENCHMARK( LoadElement );
BENCHMARK( NewElement );
BENCHMARK( SetElementName );
BENCHMARK( ElementToString );

0 comments on commit 6122a79

Please sign in to comment.