BM-8 testen ble opprinnelig publisert i US magazine Kilobaud i 1977 De ble senere adoptert i en modifisert versjon av UK magazine Personal Computer World. Testene ble målt med stoppeklokke. Når vi kjører dem på dagens PC’er, må de kjøres mange ganger for å få utslag på klokka, og her kjører vi gjennom 100 ganger.
Her er testene som kjøres
'FOR-NEXT loops are one of the commonest constructs in BASIC and if they are slow then all programs are likely to be slow. Sub Benchmark1() 20 For K = 1 To 1000 40 Next K End Sub 'This has the same effect as benchmark 1 of having the variable k count from 1 to 1000, but with explicit addition and a jump back. This method is generally much slower than the optimised FOR-NEXT loop. Notice that the benchmarks use line numbers and GOTOs. Most BASICs of the period lacked more sophisticated loop constructs. Sub Benchmark2() 20 Let K = 0 30 Let K = K + 1 50 If K < 1000 Then GoTo 30 End Sub 'This time some calculations are done inside the loop. This tests the speed of the arithmetic operators and also of accessing variables. For the benchmarks all variables are assumed to be of floating-point type. Sub Benchmark3() 20 Let K = 0 30 Let K = K + 1 40 Let a = K / K * K + K - K 50 If K < 1000 Then GoTo 30 End Sub 'The same as benchmark 3 except that constants are used for the arithmetic instead of a variable. If the code for looking up values of variables is inefficient then this test will be faster than the previous one. Sub Benchmark4() 20 Let K = 0 30 Let K = K + 1 40 Let a = K / 2 * 3 + 4 - 5 50 If K < 1000 Then GoTo 30 End Sub 'This introduces a subroutine call. It requires the return address to be put on a stack and then the destination of the call to be found, usually by searching through from the beginning of the program. Long programs in early versions of BASIC would make extensive use of subroutines and thus the efficiency of the calling mechanism was important. Sub Benchmark5() 20 Let K = 0 30 Let K = K + 1 40 Let a = K / 2 * 3 + 4 - 5 45 GoSub 700 50 If K < 1000 Then GoTo 30 60 Exit Sub 700 Return End Sub 'This defines a small array at the start and adds another FOR-NEXT loop inside the main loop. This benchmark has little importance on its own but is used as a baseline for benchmark 7. Sub Benchmark6() 20 Let K = 0 25 Dim m(5) 30 Let K = K + 1 40 Let a = K / 2 * 3 + 4 - 5 45 GoSub 700 46 For l = 1 To 5 48 Next l 50 If K < 1000 Then GoTo 30 60 Exit Sub 700 Return End Sub 'This assigns a value to each of the array elements every time through the loop. How much slower this is than benchmark 6 indicates the efficiency of array access. Sub Benchmark7() 20 Let K = 0 25 Dim m(5) 30 Let K = K + 1 40 Let a = K / 2 * 3 + 4 - 5 45 GoSub 700 46 For l = 1 To 5 47 Let m(l) = a 48 Next l 50 If K < 1000 Then GoTo 30 60 Exit Sub 700 Return End Sub 'The final benchmark uses the more advanced mathematical functions of raising to a power (usually implemented using logarithms), calculating natural logarithms and calculating trigonometric sines. Sub Benchmark8() 20 Let K = 0 25 Dim m(5) 30 Let K = K + 1 40 Let a = K * K 45 Let b = WorksheetFunction.Ln(K) 47 Let c = Sin(K) 50 If K < 1000 Then GoTo 30 End Sub
Last ned Excelfilen her: BenchMarkBM1-BM8.xlsm (32 downloads)