home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
progmisc
/
euphor10.zip
/
DATABASE.PRO
< prev
next >
Wrap
Text File
|
1993-05-12
|
4KB
|
114 lines
| -------------------------------
| -- database update benchmark --
| -------------------------------
|without type_check --makes no difference
|
|constant ITERATIONS = 1 -- was 50000
|
|-- output device
|constant LOG = 1
|
|-- update codes
|constant NEW = 1, -- add a new account
| UPDATE = 2, -- update an account
| DELETE = 3 -- delete an account
|
|-- data fields
|constant NAME = 1,
| AMOUNT = 2,
| CODE = 3
|
|sequence raw_data
1 |raw_data = {
|{"George Bush", 1000, NEW},
|{"Bill Clinton", 2000, NEW},
|{"Brian Mulroney", 500, NEW},
|{"Ross Perot", 10000, NEW},
|{"Ross Perot", 0, DELETE},
|{"George Bush", -30.55, UPDATE},
|{"Madonna", 2500, NEW},
|{"Boris Yeltsin", 100, NEW},
|{"Michael Jackson", 50, NEW},
|{"Peter Mansbridge", 1200, NEW},
|{"Bill Clinton", +500, UPDATE},
|{"Rod Stewart", 3000, NEW},
|{"Boris Yeltsin", 0, DELETE},
|{"Sharon Stone", 1500, NEW},
|{"Clint Eastwood", 1900, NEW},
|{"Madonna", 0, DELETE },
|{"Sally Jessy Raphael", 750, NEW},
|{"Brian Mulroney", -400, DELETE},
|{"Richard Gere", 299, NEW},
|{"Rod Stewart", 0, DELETE},
|{"Demi Moore", 350, NEW},
|{"Bruce Willis", 480, NEW},
|{"Sharon Stone", +900.50, UPDATE},
|{"Arsenio Hall", 300, NEW},
|{"David Letterman", 450, NEW},
|{"Whoopi Goldberg", 1050, NEW},
|{"Clint Eastwood", +2500, UPDATE},
|{"Michael Jackson", -50, UPDATE},
|{"Clint Eastwood", 0, DELETE},
|{"Jack Nicholson", 3000, NEW}
|}
|
|sequence database
1 |database = {}
|
|procedure dump()
|-- used to verify that the program has worked correctly
|-- not part of timing loop
1 | for i = 1 to length(database) do
13 | printf(LOG, "%20s: %8.2f\n", database[i])
| end for
|end procedure
|
|procedure purge()
|-- empty the database - free all storage
1 | database = {}
|end procedure
|
|procedure update(sequence data_stream)
|-- process a series of transactions
| integer action, account_no
| sequence pname, record
|
1 | for i = 1 to length(data_stream) do
30 | record = data_stream[i]
30 | action = record[CODE]
|
30 | if action = NEW then
19 | database = append(database, record[NAME..AMOUNT])
|
| else
| -- look up name
11 | pname = record[NAME]
11 | for j = 1 to length(database) do
44 | if compare(pname, database[j][NAME]) = 0 then
11 | account_no = j
11 | exit
| end if
| end for
|
11 | if action = UPDATE then
5 | database[account_no][AMOUNT] = database[account_no][AMOUNT] +
| record[AMOUNT]
|
6 | elsif action = DELETE then
6 | database = database[1..account_no-1] &
| database[account_no+1..length(database)]
| end if
| end if
| end for
|end procedure
|
|atom t
1 |t = time()
1 |for i = 1 to ITERATIONS do
1 | purge()
1 | update(raw_data)
|end for
1 |printf(1, "%d iterations in %.2f seconds\n", {ITERATIONS, time() - t})
1 |dump()