PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/examples/benchmarks/retrieving_benchmark.e

http://github.com/tybor/Liberty
Specman e | 108 lines | 91 code | 16 blank | 1 comment | 5 complexity | d1f78a778f863d34134fc9600281cc12 MD5 | raw file
  1indexing
  2	description: "Benchmark for boosted property setter"
  3	copyright: "[
  4					Copyright (C) 2006 Paolo Redaelli
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20					]"
 21
 22class RETRIEVING_BENCHMARK
 23
 24inherit WRAPPER_HANDLER
 25
 26insert
 27	SHARED_WRAPPERS_DICTIONARY
 28	GTK
 29	ARGUMENTS
 30	MEMORY
 31	
 32creation make
 33
 34feature -- objects and 
 35	timer: G_TIMER
 36	label: GTK_LABEL
 37	labels: FAST_ARRAY [GTK_LABEL]
 38	pointer: POINTER
 39
 40	random: STD_RAND
 41	
 42feature
 43	iterations_number: INTEGER_32
 44	
 45	make is
 46		local i: INTEGER
 47		do
 48			if (argument_count>0 and then argument(1).is_integer)
 49			 then iterations_number := argument(1).to_integer
 50			else iterations_number := 10000
 51			end
 52			print ("Iterations:%TWrappers%TRetriever%TMemory usage%N")
 53			print (iterations_number.out) print ("%T")
 54
 55			gtk.initialize
 56			create timer
 57			create random.make
 58			-- Create labels
 59			from create labels.make (iterations_number); i:=iterations_number-1
 60			until i < 0
 61			loop
 62				create label.with_label("Label n. "+i.out)
 63				labels.put(label, i)
 64				wrappers.add (label, label.handle)
 65				i := i-1
 66			end
 67
 68			wrapper_benchmark
 69			retriever_benchmark
 70
 71			print (allocated_bytes.out) print ("%N")
 72		ensure iterations_number /= 0
 73		end
 74
 75	wrapper_benchmark is
 76		local counter: INTEGER; l: GTK_LABEL
 77		do	
 78			from counter := iterations_number; timer.start
 79			until counter = 0
 80			loop
 81				random.next
 82				label := labels.item(random.last_integer(iterations_number-1))
 83				pointer := label.handle
 84				l ::= wrappers.at(pointer)
 85				check l_is_label: l = label end
 86				counter := counter - 1
 87			end
 88			timer.stop
 89			print (timer.elapsed.out) print ("%T")
 90		end
 91
 92	retriever_benchmark is
 93		local counter: INTEGER; l: GTK_LABEL; r: G_RETRIEVER[GTK_LABEL]
 94		do	
 95			from counter := iterations_number; timer.start
 96			until counter = 0
 97			loop
 98				random.next
 99				label := labels.item(random.last_integer(iterations_number-1))
100				pointer := label.handle
101				l := r.wrapper(pointer)
102				check l_is_label: l = label end
103				counter := counter - 1
104			end
105			timer.stop
106			print (timer.elapsed.out)  print ("%T")
107		end 
108end