/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

  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 RETRIEVING_BENCHMARK
  19. inherit WRAPPER_HANDLER
  20. insert
  21. SHARED_WRAPPERS_DICTIONARY
  22. GTK
  23. ARGUMENTS
  24. MEMORY
  25. creation make
  26. feature -- objects and
  27. timer: G_TIMER
  28. label: GTK_LABEL
  29. labels: FAST_ARRAY [GTK_LABEL]
  30. pointer: POINTER
  31. random: STD_RAND
  32. feature
  33. iterations_number: INTEGER_32
  34. make is
  35. local i: INTEGER
  36. do
  37. if (argument_count>0 and then argument(1).is_integer)
  38. then iterations_number := argument(1).to_integer
  39. else iterations_number := 10000
  40. end
  41. print ("Iterations:%TWrappers%TRetriever%TMemory usage%N")
  42. print (iterations_number.out) print ("%T")
  43. gtk.initialize
  44. create timer
  45. create random.make
  46. -- Create labels
  47. from create labels.make (iterations_number); i:=iterations_number-1
  48. until i < 0
  49. loop
  50. create label.with_label("Label n. "+i.out)
  51. labels.put(label, i)
  52. wrappers.add (label, label.handle)
  53. i := i-1
  54. end
  55. wrapper_benchmark
  56. retriever_benchmark
  57. print (allocated_bytes.out) print ("%N")
  58. ensure iterations_number /= 0
  59. end
  60. wrapper_benchmark is
  61. local counter: INTEGER; l: GTK_LABEL
  62. do
  63. from counter := iterations_number; timer.start
  64. until counter = 0
  65. loop
  66. random.next
  67. label := labels.item(random.last_integer(iterations_number-1))
  68. pointer := label.handle
  69. l ::= wrappers.at(pointer)
  70. check l_is_label: l = label end
  71. counter := counter - 1
  72. end
  73. timer.stop
  74. print (timer.elapsed.out) print ("%T")
  75. end
  76. retriever_benchmark is
  77. local counter: INTEGER; l: GTK_LABEL; r: G_RETRIEVER[GTK_LABEL]
  78. do
  79. from counter := iterations_number; timer.start
  80. until counter = 0
  81. loop
  82. random.next
  83. label := labels.item(random.last_integer(iterations_number-1))
  84. pointer := label.handle
  85. l := r.wrapper(pointer)
  86. check l_is_label: l = label end
  87. counter := counter - 1
  88. end
  89. timer.stop
  90. print (timer.elapsed.out) print ("%T")
  91. end
  92. end