BBS: Inland Empire Archive Date: 06-10-92 (00:00) Number: 165 From: QUINN TYLER JACKSON Refer#: NONE To: MIKE KRUPPENBACHER Recvd: NO Subj: Re: Arrays Conf: (2) Quik_Bas
MK>I really, really wish people would QUANTIFY instead of MK>EMOTIONALIZING.. it would help a LOT if you SHOWED WHY its MK>slower and HOW MUCH slower.. (if its .000000001% who CARES? MK> if its 10 TIMES slower, what works better and by how much?) MK>Not really to you particularly, I keep getting jumped on MK>with things like this, and I really, really wish people MK>would begin to act like PROGRAMMERS and QUANTIFY! Inspired by your plea, I wrote TYPETEST.BAS, which does exactly what you ask. On my computer, anyway, at 12MHZ there is VERY LITTLE difference in access time. Try it out on yours.... Vive la HardScience! Quinn --------->8 CUT HERE 8<---------- DECLARE FUNCTION TotalTime% (start$, end$) ' Okay, Drask, here is a test of STATIC versus DYNAMIC array access ' time ' TYPETEST.BAS v1.0 released into the public domain June 1992 ' By Quinn Tyler Jackson ' N.B.... to be a truly accurate test, this test must be COMPILED, since ' STATIC and DYNAMIC are compiler directives DEFINT A-Z OPTION BASE 1 CLS ' Set up a STATIC and DYNAMIC array '$STATIC DIM staticArray(1000) '$DYNAMIC DIM dynamicArray(1000) 'Assign random values to the elements of each FOR count = 1 TO 1000 staticArray(count) = RND * 32000 dynamicArray(count) = RND * 32000 NEXT count 'Now, to access the staticArray 30,000 times, and see how long it takes.... startTime$ = TIME$ FOR count = 1 TO 30000 ptr = 1 + (RND * 999) nul = staticArray(ptr) NEXT endTime$ = TIME$ PRINT "Static test started---> "; startTime$ PRINT "Static test ended-----> "; endTime$ staticTime = TotalTime(startTime$, endTime$) PRINT "Static access time----> "; staticTime PRINT PRINT "--------" PRINT 'Now, to access the dynamicArray 30,000 times and compare the results.... startTime$ = TIME$ FOR count = 1 TO 30000 ptr = 1 + (RND * 999) nul = dynamicArray(ptr) NEXT endTime$ = TIME$ PRINT "Dynamic test started---> "; startTime$ PRINT "Dynamic test ended-----> "; endTime$ dynamicTime = TotalTime(startTime$, endTime$) PRINT "Dynamic access time----> "; dynamicTime PRINT PRINT "---------" PRINT timeDiff = dynamicTime - staticTime PRINT "Time difference--------> "; timeDiff END REM $STATIC FUNCTION TotalTime (start$, end$) ' This function returns the total time elapsed between two points in ' that are in "hh:mm:ss" string format startSecond = VAL(RIGHT$(start$, 2)) startMinute = VAL(MID$(start$, 4, 2)) startHour = VAL(LEFT$(start$, 2)) endSecond = VAL(RIGHT$(end$, 2)) endMinute = VAL(MID$(end$, 4, 2)) endHour = VAL(LEFT$(end$, 2)) TotalTime = (endSecond - startSecond) + ((endMinute - startMinute) * 60) + ((en END FUNCTION * SLMR 2.1a * Deuteronomy as you would have him do unto you.... --- Maximus/2 2.01wb * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET