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

http://github.com/tybor/Liberty · Specman e · 152 lines · 120 code · 28 blank · 4 comment · 5 complexity · 53e63e94079925071401e0674d5b7128 MD5 · raw file

  1. indexing
  2. description: "Benchmark for boosted property setter"
  3. copyright: "[
  4. Copyright (C) 2006 Paolo Redaelli
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. class PROPERTY_BENCHMARK
  19. insert
  20. GTK
  21. ARGUMENTS
  22. PANGO_CONSTANTS
  23. PANGO_SCALES
  24. PANGO_WEIGHT
  25. PANGO_STYLE
  26. creation make
  27. feature -- Widgets
  28. buffer: GTK_TEXT_BUFFER
  29. timer: G_TIMER
  30. feature
  31. iterations_number: INTEGER_32
  32. make is
  33. do
  34. if (argument_count > 0 and then
  35. argument(1).is_integer) then
  36. iterations_number := argument(1).to_integer
  37. else
  38. iterations_number := 10000
  39. end
  40. print ("Doing ") print (iterations_number.out)
  41. print (" iterations%N")
  42. gtk.initialize
  43. create buffer.make
  44. create timer
  45. create bold_value.from_integer(pango_weight_bold)
  46. create size_value.from_integer(15 * 1024)
  47. create style_value.from_integer(pango_style_italic)
  48. weight_value := bold_value
  49. smart_setter_benchmark
  50. normal_setter_benchmark
  51. ensure
  52. iterations_number /= 0
  53. end
  54. weight_p, size_p, style_p: G_PARAM_SPEC
  55. bold_value, size_value, style_value, weight_value: G_VALUE
  56. smart_setter_benchmark is
  57. require
  58. bold_value/=Void
  59. size_value/=Void
  60. style_value/=Void
  61. weight_value/=Void
  62. iterations_number > 100
  63. local counter: INTEGER
  64. do
  65. weight_p := heading.find_property (once "weight")
  66. size_p := heading.find_property (once "size")
  67. from counter := iterations_number; timer.start
  68. until counter = 0
  69. loop
  70. heading.smart_set_property (weight_p, bold_value)
  71. heading.smart_set_property (size_p, size_value)
  72. --italic.smart_set_property (once "style",style_value)
  73. bold.smart_set_property (weight_p, bold_value)
  74. counter := counter - 1
  75. end
  76. timer.stop
  77. print ("Using Eiffel implementation of property set took ")
  78. print (timer.elapsed.out) print (" seconds.%N")
  79. end
  80. normal_setter_benchmark is
  81. require
  82. bold_value/=Void
  83. size_value/=Void
  84. style_value/=Void
  85. weight_value/=Void
  86. iterations_number > 100
  87. local counter: INTEGER
  88. do
  89. from counter := iterations_number; timer.start
  90. until counter = 0
  91. loop
  92. heading.set_property (once "weight", bold_value)
  93. heading.set_property (once "size", size_value)
  94. --italic.set_property (once "style", style_value)
  95. bold.set_property (once "weight", bold_value)
  96. counter := counter - 1
  97. end
  98. timer.stop
  99. print ("Using original implementation of property set took ")
  100. print (timer.elapsed.out) print (" seconds.%N")
  101. end
  102. feature -- tags
  103. heading: GTK_TEXT_TAG is
  104. once
  105. create Result.with_name("heading")
  106. end
  107. italic: GTK_TEXT_TAG is
  108. once
  109. create Result.with_name("italic")
  110. -- Result.set_style (pango_style_italic)
  111. end
  112. bold: GTK_TEXT_TAG is
  113. once
  114. create Result.with_name("bold")
  115. -- Result.set_weight ( pango_weight_bold )
  116. end
  117. tags: GTK_TEXT_TAG_TABLE is
  118. once
  119. create Result.make
  120. Result.add (heading)
  121. Result.add (italic)
  122. Result.add (bold)
  123. end
  124. end