home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / DATABASE.EX < prev    next >
Text File  |  1993-06-01  |  3KB  |  113 lines

  1.             -------------------------------
  2.             -- database update benchmark --
  3.             -------------------------------
  4. without type_check -- makes no difference
  5.  
  6. constant ITERATIONS = 50000
  7.  
  8. -- output device
  9. constant LOG = 1
  10.  
  11. -- update codes
  12. constant NEW = 1,    -- add a new account
  13.      UPDATE = 2, -- update an account
  14.      DELETE = 3  -- delete an account
  15.  
  16. -- data fields
  17. constant NAME = 1,
  18.      AMOUNT = 2,
  19.      CODE = 3
  20.  
  21. sequence raw_data 
  22. raw_data = {
  23. {"George Bush", 1000, NEW},
  24. {"Bill Clinton", 2000, NEW},
  25. {"Brian Mulroney", 500, NEW},
  26. {"Ross Perot", 10000, NEW},
  27. {"Ross Perot", 0, DELETE},
  28. {"George Bush", -30.55, UPDATE},
  29. {"Madonna", 2500, NEW},
  30. {"Boris Yeltsin", 100, NEW},
  31. {"Michael Jackson", 50, NEW},
  32. {"Peter Mansbridge", 1200, NEW},
  33. {"Bill Clinton", +500, UPDATE},
  34. {"Rod Stewart", 3000, NEW},
  35. {"Boris Yeltsin", 0, DELETE},
  36. {"Sharon Stone", 1500, NEW},
  37. {"Clint Eastwood", 1900, NEW},
  38. {"Madonna", 0, DELETE },
  39. {"Sally Jessy Raphael", 750, NEW},
  40. {"Brian Mulroney", -400, DELETE},
  41. {"Richard Gere", 299, NEW},
  42. {"Rod Stewart", 0, DELETE},
  43. {"Demi Moore", 350, NEW},
  44. {"Bruce Willis", 480, NEW},
  45. {"Sharon Stone", +900.50, UPDATE},
  46. {"Arsenio Hall", 300, NEW},
  47. {"David Letterman", 450, NEW},
  48. {"Whoopi Goldberg", 1050, NEW},
  49. {"Clint Eastwood", +2500, UPDATE},
  50. {"Michael Jackson", -50, UPDATE},
  51. {"Clint Eastwood", 0, DELETE},
  52. {"Jack Nicholson", 3000, NEW}
  53. }
  54.  
  55. sequence database 
  56. database = {}
  57.  
  58. procedure dump()
  59. -- used to verify that the program has worked correctly
  60. -- not part of timing loop
  61.     for i = 1 to length(database) do
  62.     printf(LOG, "%20s: %8.2f\n", database[i])
  63.     end for
  64. end procedure
  65.  
  66. procedure purge()
  67. -- empty the database - free all storage
  68.     database = {}
  69. end procedure
  70.  
  71. procedure update(sequence data_stream)
  72. -- process a series of transactions
  73.     integer action, account_no
  74.     sequence pname, record
  75.  
  76.     for i = 1 to length(data_stream) do
  77.     record = data_stream[i]
  78.     action = record[CODE]
  79.     
  80.     if action = NEW then
  81.         database = append(database, record[NAME..AMOUNT])
  82.  
  83.     else 
  84.         -- look up name
  85.         pname = record[NAME]
  86.         for j = 1 to length(database) do
  87.         if compare(pname, database[j][NAME]) = 0 then
  88.             account_no = j
  89.             exit
  90.         end if
  91.         end for
  92.  
  93.         if action = UPDATE then
  94.         database[account_no][AMOUNT] = database[account_no][AMOUNT] + 
  95.                            record[AMOUNT]
  96.  
  97.         elsif action = DELETE then
  98.         database = database[1..account_no-1] & 
  99.                database[account_no+1..length(database)]
  100.         end if
  101.     end if
  102.     end for        
  103. end procedure
  104.  
  105. atom t
  106. t = time()
  107. for i = 1 to ITERATIONS do
  108.     purge()
  109.     update(raw_data)
  110. end for
  111. printf(1, "%d iterations in %.2f seconds\n", {ITERATIONS, time() - t})
  112. dump()
  113.