Exercises

Index Speed Tests

In the Inspector, create a soup containing 200 entries. Each entry specifies one order and contains two slots:

itemNumber
an integer between 1000 and 9999

dollarAmount:
an integer between 4 and 40

Use random values for both the item numbers and the dollar amounts. Create indexes on both the itemNumber and dollarAmount slots.

Once you've created the soup, write code that finds how many items there are whose dollarAmount is 17. Time your code to see how long it takes. Make improvements until you've got it as fast as possible.

Now write code that prints out each item whose dollarAmount is 17 sorted by itemNumber. How long does that take?

Add an index to the soup to speed up printing out each item whose dollarAmount is 17 sorted by itemNumber. How fast can you do it now?


Note:Generate random numbers using the Random global function. Call it with Random(lowRange, highRange) to return an integer between lowRange and highRange.
Then time your code with the Ticks global function. It returns an integer that increases by one every 60th of a second.


A QuickTime movie of the solution is available.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996