-- A V Peterson 05-2001 -- AVP minor mods 05-2002 class TIME_SORT -- Test bed for testing time efficiency of various sorting algorithms creation make feature a : ARRAY[INTEGER] size : INTEGER sorter : MY_SORTER -- sorter : COLLECTION_SORTER[INTEGER] make is local timer : BASIC_TIME -- system clock clock_start, clock_end : INTEGER do !!timer io.put_string("Size of array : ") io.read_integer; size := io.last_integer !!a.make(1, size) fill_rand -- fill_ord -- fill_rev -- print_a !!sorter clock_start := timer.clock_periods -- *** call sort routine here *** -- sorter.selection_sort(a) -- Some sorting routines available in the MY_SORTER class -- sorter.insertion_sort(a) -- sorter.selection_sort(a) sorter.quick_sort(a) -- sorter.gap_sort(a) -- sorter.heap_sort(a) -- sorter.thing_sort(a) -- print_a clock_end := timer.clock_periods -- report elapsed time in sec (no of clock periods/1000000) io.put_string(" ") io.put_integer(clock_start) io.put_string(" ") io.put_integer(clock_end) io.put_string(" ") io.put_double_format((clock_end - clock_start)/1000000, 2) io.put_new_line end -- make fill_rand is -- Fill array a with size random numbers. local i : INTEGER seed : INTEGER rand : STD_RAND do io.put_string("Seed : ") io.read_integer; seed := io.last_integer !!rand.with_seed(seed) from i := 1 until i > size loop rand.next a.put(rand.last_integer(10000), i) i := i + 1 end -- loop end -- fill_rand fill_ord is -- Fill array a with numbers 1 to size in increasing order. local i : INTEGER do from i := 1 until i > size loop a.put(i, i) i := i + 1 end -- loop end -- fill_ord fill_rev is -- Fill array a with numbers size down to 1 (decreasing order). local i : INTEGER do from i := 1 until i > size loop a.put(size+1-i, i) i := i + 1 end -- loop end -- fill_rev print_a is local i : INTEGER do from i := a.lower until i > a.upper loop io.put_integer_format(a.item(i), 6) if i\\10 = 0 then io.put_new_line end i := i + 1 end -- loop io.put_new_line end -- print_a end -- class TIME_SORT