/src/wrappers/gtk/examples/benchmarks/property_benchmark.e
Specman e | 152 lines | 120 code | 28 blank | 4 comment | 5 complexity | 53e63e94079925071401e0674d5b7128 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 PROPERTY_BENCHMARK 23 24insert 25 GTK 26 ARGUMENTS 27 28 PANGO_CONSTANTS 29 PANGO_SCALES 30 PANGO_WEIGHT 31 PANGO_STYLE 32 33creation make 34 35feature -- Widgets 36 buffer: GTK_TEXT_BUFFER 37 38 timer: G_TIMER 39 40feature 41 iterations_number: INTEGER_32 42 43 make is 44 do 45 if (argument_count > 0 and then 46 argument(1).is_integer) then 47 iterations_number := argument(1).to_integer 48 else 49 iterations_number := 10000 50 end 51 print ("Doing ") print (iterations_number.out) 52 print (" iterations%N") 53 54 gtk.initialize 55 create buffer.make 56 create timer 57 58 create bold_value.from_integer(pango_weight_bold) 59 create size_value.from_integer(15 * 1024) 60 create style_value.from_integer(pango_style_italic) 61 weight_value := bold_value 62 63 smart_setter_benchmark 64 normal_setter_benchmark 65 ensure 66 iterations_number /= 0 67 end 68 69 weight_p, size_p, style_p: G_PARAM_SPEC 70 bold_value, size_value, style_value, weight_value: G_VALUE 71 72 smart_setter_benchmark is 73 require 74 bold_value/=Void 75 size_value/=Void 76 style_value/=Void 77 weight_value/=Void 78 iterations_number > 100 79 local counter: INTEGER 80 do 81 weight_p := heading.find_property (once "weight") 82 size_p := heading.find_property (once "size") 83 from counter := iterations_number; timer.start 84 until counter = 0 85 loop 86 heading.smart_set_property (weight_p, bold_value) 87 heading.smart_set_property (size_p, size_value) 88 89 --italic.smart_set_property (once "style",style_value) 90 91 bold.smart_set_property (weight_p, bold_value) 92 93 counter := counter - 1 94 end 95 timer.stop 96 print ("Using Eiffel implementation of property set took ") 97 print (timer.elapsed.out) print (" seconds.%N") 98 end 99 100 normal_setter_benchmark is 101 require 102 bold_value/=Void 103 size_value/=Void 104 style_value/=Void 105 weight_value/=Void 106 iterations_number > 100 107 local counter: INTEGER 108 do 109 from counter := iterations_number; timer.start 110 until counter = 0 111 loop 112 heading.set_property (once "weight", bold_value) 113 heading.set_property (once "size", size_value) 114 115 --italic.set_property (once "style", style_value) 116 117 bold.set_property (once "weight", bold_value) 118 119 counter := counter - 1 120 end 121 timer.stop 122 print ("Using original implementation of property set took ") 123 print (timer.elapsed.out) print (" seconds.%N") 124 end 125 126feature -- tags 127 heading: GTK_TEXT_TAG is 128 once 129 create Result.with_name("heading") 130 end 131 132 italic: GTK_TEXT_TAG is 133 once 134 create Result.with_name("italic") 135 -- Result.set_style (pango_style_italic) 136 end 137 138 bold: GTK_TEXT_TAG is 139 once 140 create Result.with_name("bold") 141 -- Result.set_weight ( pango_weight_bold ) 142 end 143 144 tags: GTK_TEXT_TAG_TABLE is 145 once 146 create Result.make 147 Result.add (heading) 148 Result.add (italic) 149 Result.add (bold) 150 end 151 152end