home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / sequence.ex < prev    next >
Text File  |  1994-03-09  |  3KB  |  121 lines

  1. -- Sequence Operations Benchmarks 
  2.  
  3. without type_check
  4.  
  5. constant BENCH_TIME = 15   -- run for at least this many seconds
  6. constant SIZE = 100        -- sequence size for init, add
  7.  
  8. -- We check the time after performing each "batch". The overhead of checking
  9. -- the time should be negligible. However we should check often enough so 
  10. -- a very slow machine running QBasic does not take too long to perform a 
  11. -- single batch.
  12. constant INIT_BATCH = 2000 
  13. constant ADD_BATCH = 1000 
  14. constant LOOKUP_BATCH = 2000
  15. constant SLICE_BATCH = 5
  16. constant CONCAT_BATCH = 5
  17.  
  18. constant CONCAT_SIZE = 5000 -- maximum sequence size
  19. constant SCREEN = 1
  20.  
  21. atom t, cycles
  22.  
  23. puts(SCREEN, "\n\t\tEuphoria Sequence Benchmarks\n")
  24.  
  25. sequence x, y, z
  26.  
  27. printf(SCREEN, "\n* Initializing a length-%d sequence ---> ", SIZE)
  28. cycles = 0
  29. t = time()
  30. while time() < t + BENCH_TIME do
  31.     for j = 1 to INIT_BATCH do
  32.     z = repeat(999, SIZE)
  33.     end for
  34.     cycles = cycles + INIT_BATCH
  35. end while
  36. t = time() - t
  37. printf(SCREEN, "%d initializations per second\n", cycles / t)
  38.  
  39.  
  40. printf(SCREEN, "\n* Adding two length-%d sequences ---> ", SIZE)
  41.  
  42. x = rand(repeat(999, SIZE))
  43. y = rand(repeat(999, SIZE))
  44.  
  45. cycles = 0
  46. t = time()
  47. while time() < t + BENCH_TIME do
  48.     for j = 1 to ADD_BATCH do
  49.     z = x + y   -- add two sequences
  50.     end for
  51.     cycles = cycles + ADD_BATCH
  52. end while
  53. t = time() - t
  54. printf(SCREEN, "%5d sequence-adds per second\n", cycles / t)
  55.  
  56. puts(SCREEN, "\n* Appending to a sequence ---> ")
  57. sequence s
  58. cycles = 0
  59. t = time()
  60. while time() < t + BENCH_TIME do
  61.     for j = 1 to CONCAT_BATCH do
  62.         s = ""
  63.         for k = 1 to CONCAT_SIZE do
  64.             s = append(s, '*')
  65.         end for
  66.     end for
  67.     cycles = cycles + CONCAT_BATCH * CONCAT_SIZE
  68. end while
  69. t = time() - t
  70. printf(SCREEN, "%d appends per second\n", cycles / t)
  71.  
  72.  
  73. puts(SCREEN, "\n* Slicing a sequence ---> ")
  74. sequence partial
  75. cycles = 0
  76. t = time()
  77. while time() < t + BENCH_TIME do
  78.     for j = 1 to SLICE_BATCH do
  79.         partial = s 
  80.         while length(partial) >= 2 do
  81.         -- delete an element from each end
  82.         partial = partial[2..length(partial)-1]
  83.         end while
  84.     end for
  85.     cycles = cycles + SLICE_BATCH * length(s) / 2
  86. end while
  87. t = time() - t
  88. printf(SCREEN, "%d slices per second\n", cycles / t)
  89.  
  90.  
  91. puts(SCREEN, "\n* Name look-up ---> ")
  92.  
  93. sequence states
  94. states = {
  95.   "Kentucky", "Alabama", "California", "Washington", "Ohio", "Texas",
  96.   "Nevada", "Florida", "Wyoming", "New York", "Maine", "Massachusetts",
  97.   "North Carolina", "South Carolina", "North Dakota", "South Dakota",
  98.   "Mississippi", "Arizona", "Hawaii", "Alaska", "Oregon", "Michigan",
  99.   "Illinois", "Pennsylvania", "Kansas", "Virginia", "New Mexico", 
  100.   "Rhode Island", "New Hampshire", "Delaware", "Tennessee", "Colorado",
  101.   "Wisconsin", "Vermont", "Indiana", "Maryland", "Connecticut", "Louisiana",
  102.   "Missouri", "Minnesota", "Iowa", "Idaho", "Arkansas", "Montana",
  103.   "Nebraska", "Georgia", "West Virginia", "Utah", "New Jersey",  "Oklahoma"
  104. }
  105.  
  106. cycles = 0
  107. t = time()
  108. while time() < t + BENCH_TIME do
  109.     for i = 1 to LOOKUP_BATCH do
  110.     if find("Oklahoma", states) != 50 then
  111.         puts(SCREEN, "whoops!\n")
  112.     end if
  113.     end for
  114.     cycles = cycles + LOOKUP_BATCH
  115. end while
  116. t = time() - t
  117. printf(SCREEN, "%d look-ups per second\n", cycles / t)
  118.  
  119. without warning
  120.  
  121.