From: rich Date: Thu, 11 Oct 2007 07:45:35 +0000 (+0000) Subject: Wrote code to do performance comparisons. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=aa173d5f30ea45f0c06799c858c4a91681cf0cf7;p=jonesforth.git Wrote code to do performance comparisons. --- diff --git a/Makefile b/Makefile index f5a7494..d47b4d2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.7 2007-10-10 13:01:05 rich Exp $ +# $Id: Makefile,v 1.8 2007-10-11 07:45:35 rich Exp $ SHELL := /bin/bash @@ -11,7 +11,7 @@ run: cat jonesforth.f $(PROG) - | ./jonesforth clean: - rm -f jonesforth *~ core .test_* + rm -f jonesforth perf_dupdrop *~ core .test_* # Tests. @@ -34,8 +34,11 @@ test_%.test: test_%.f jonesforth perf_dupdrop: perf_dupdrop.c gcc -O3 -Wall -Werror -o $@ $< +run_perf_dupdrop: jonesforth + cat <(echo ': TEST-MODE ;') jonesforth.f perf_dupdrop.f | ./jonesforth + .SUFFIXES: .f .test -.PHONY: test check +.PHONY: test check run run_perf_dupdrop remote: scp jonesforth.S jonesforth.f rjones@oirase:Desktop/ diff --git a/perf_dupdrop.f b/perf_dupdrop.f index 8b0d911..9841538 100644 --- a/perf_dupdrop.f +++ b/perf_dupdrop.f @@ -1,5 +1,72 @@ ( -*- text -*- FORTH repeated DUP DROP * 1000 using ordinary indirect threaded code and the assembler primitives. - $Id: perf_dupdrop.f,v 1.1 2007-10-10 13:01:05 rich Exp $ ) + $Id: perf_dupdrop.f,v 1.2 2007-10-11 07:45:35 rich Exp $ ) +1024 32 * MORECORE + +( Print the time passed. ) +: PRINT-TIME ( lsb msb lsb msb -- lsb lsb ) + ( The test is very short so likely the MSBs will be the same. This + makes calculating the time easier (because we can only do 32 bit + subtraction). So check MSBs are equal. ) + 2 PICK <> IF + ." MSBs not equal, please repeat the test" CR + ELSE + NIP + SWAP - U. CR + THEN +; + +: PERFORM-TEST ( xt -- ) + ( Get everything in the cache. ) + DUP EXECUTE DUP EXECUTE DUP EXECUTE DUP EXECUTE DUP EXECUTE DUP EXECUTE + 0 0 0 0 PRINT-TIME + ( Run the test 10 times. ) + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DUP EXECUTE PRINT-TIME + DROP +; + +( ---------------------------------------------------------------------- ) +( Make a word which builds the repeated DUP DROP sequence. ) +: MAKE-DUPDROP ( n -- ) + BEGIN ?DUP WHILE ' DUP , ' DROP , 1- REPEAT +; + +( Now the actual test routine. ) +: TEST ( -- startlsb startmsb endlsb endmsb ) + RDTSC ( Start time ) + [ 1000 MAKE-DUPDROP ] ( 1000 * DUP DROP ) + RDTSC ( End time ) +; + +: RUN ['] TEST PERFORM-TEST ; +RUN + +( ---------------------------------------------------------------------- ) +( Try the inlined alternative. ) + +( Inline the assembler primitive (cfa) n times. ) +: *(INLINE) ( cfa n -- ) + BEGIN ?DUP WHILE OVER (INLINE) 1- REPEAT DROP +; + +: DUPDROP INLINE DUP INLINE DROP ;CODE + +: TEST + INLINE RDTSC + [ S" DUPDROP" FIND >CFA 1000 *(INLINE) ] + INLINE RDTSC +;CODE + +: RUN ['] TEST PERFORM-TEST ; +RUN