2 FORTH repeated DUP DROP * 1000 using ordinary indirect threaded code
3 and the assembler primitives.
4 $Id: perf_dupdrop.f,v 1.3 2007-10-12 01:46:26 rich Exp $ )
8 ( Print the time passed. )
9 : PRINT-TIME ( lsb msb lsb msb -- lsb lsb )
10 ( The test is very short so likely the MSBs will be the same. This
11 makes calculating the time easier (because we can only do 32 bit
12 subtraction). So check MSBs are equal. )
14 ." MSBs not equal, please repeat the test" CR
21 : 4DROP DROP DROP DROP DROP ;
23 : PERFORM-TEST ( xt -- )
24 ( Get everything in the cache. )
32 ( Run the test 10 times. )
33 DUP EXECUTE PRINT-TIME
34 DUP EXECUTE PRINT-TIME
35 DUP EXECUTE PRINT-TIME
36 DUP EXECUTE PRINT-TIME
37 DUP EXECUTE PRINT-TIME
38 DUP EXECUTE PRINT-TIME
39 DUP EXECUTE PRINT-TIME
40 DUP EXECUTE PRINT-TIME
41 DUP EXECUTE PRINT-TIME
42 DUP EXECUTE PRINT-TIME
46 ( ---------------------------------------------------------------------- )
47 ( Make a word which builds the repeated DUP DROP sequence. )
48 : MAKE-DUPDROP ( n -- )
49 BEGIN ?DUP WHILE ' DUP , ' DROP , 1- REPEAT
52 ( Now the actual test routine. )
53 : TEST ( -- startlsb startmsb endlsb endmsb )
55 [ 1000 MAKE-DUPDROP ] ( 1000 * DUP DROP )
59 : RUN ['] TEST PERFORM-TEST ;
62 ( ---------------------------------------------------------------------- )
63 ( Try the inlined alternative. )
65 ( Inline the assembler primitive (cfa) n times. )
66 : *(INLINE) ( cfa n -- )
67 BEGIN ?DUP WHILE OVER (INLINE) 1- REPEAT DROP
70 : DUPDROP INLINE DUP INLINE DROP ;CODE
74 [ S" DUPDROP" FIND >CFA 1000 *(INLINE) ]
78 : RUN ['] TEST PERFORM-TEST ;