// /*--------------------------------------------------------*\ // | Main Program: Test of clearing Text using a loop // |*--------------------------------------------------------*| // | Date: 25 April 1997 // | Author: Bruce W. Weide // | // | Brief User's Manual: // | Time this using "time Loop" and compare with Swap.cpp // | Clear.cpp. // | // \*--------------------------------------------------------*/ ///------------------------------------------------------------- /// Global Context --------------------------------------------- ///------------------------------------------------------------- #include "RESOLVE_Foundation.h" #include "CI/Timer/1.h" ///------------------------------------------------------------- /// Interface -------------------------------------------------- ///------------------------------------------------------------- global_procedure Clear ( consumes Text& t ); //---------------------------------------------------------------------- global_procedure_body Clear ( consumes Text& t ) { while (t.Length () > 0) { object Character c; t.Remove (0, c); } } //-------------------------------------------------------------- program_body main () { object Character_IStream input; object Character_OStream output; object Timer_1 timer; object Integer length_of_t, number_of_trials, n, total_clear_time, total_destructor_time; input.Open_External (""); output.Open_External (""); output << "Length of Text object: "; input >> length_of_t; output << "Number of trials: "; input >> number_of_trials; while (n < number_of_trials) { { object Text t; while (t.Length () < length_of_t) { t.Add (0, 'x'); } n++; timer.Restart (); Clear (t); total_clear_time += timer.Reading (); timer.Restart (); } total_destructor_time += timer.Reading (); } output << "Clear (t) (implemented by removing each character): " << total_clear_time * 1000 / number_of_trials << " usec\n"; output << "Destructor for t: " << total_destructor_time * 1000 / number_of_trials << " usec\n"; input.Close_External (); output.Close_External (); }