2008-09-10 23:11:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: kernel sequences namespaces make math assocs words arrays
							 | 
						
					
						
							
								
									
										
										
										
											2008-11-23 04:10:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								tools.annotations vocabs sorting prettyprint io system
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-18 18:01:26 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								math.statistics accessors tools.time fry ;
							 | 
						
					
						
							
								
									
										
										
										
											2011-09-18 22:00:30 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FROM: namespaces => change-global ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: wordtimer
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								SYMBOL: *wordtimes*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								SYMBOL: *calling*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: reset-word-timer ( -- ) 
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    H{ } clone *wordtimes* set-global
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    H{ } clone *calling* set-global ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: lookup-word-time ( wordname -- utime n )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    *wordtimes* get-global [ drop { 0 0 } ] cache first2 ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: update-times ( utime current-utime current-numinvokes -- utime' invokes' )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    rot [ + ] curry [ 1 + ] bi* ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: register-time ( utime word -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    name>>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ lookup-word-time update-times 2array ] keep *wordtimes* get-global set-at ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: calling ( word -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup *calling* get-global set-at ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: finished ( word -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    *calling* get-global delete-at ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: called-recursively? ( word -- t/f )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    *calling* get-global at ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: timed-call ( quot word -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ calling ] [ [ benchmark ] dip register-time ] [ finished ] tri ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: time-unless-recursing ( quot word -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup called-recursively? not
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ timed-call ] [ drop call ] if ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: (add-timer) ( word quot -- quot' )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ swap time-unless-recursing ] 2curry ; 
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: add-timer ( word -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup '[ [ _ ] dip (add-timer) ] annotate ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-30 14:31:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: add-timers ( vocab -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    words [ add-timer ] each ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-30 14:31:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: reset-vocab ( vocab -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    words [ reset ] each ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: dummy-word ( -- ) ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: time-dummy-word ( -- n )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ 100000 [ [ dummy-word ] benchmark , ] times ] { } make median ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: subtract-overhead ( {oldtime,n} overhead -- {newtime,n} )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ first2 ] dip
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    swap [ * - ] keep 2array ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: (correct-for-timing-overhead) ( timingshash -- timingshash )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    time-dummy-word [ subtract-overhead ] curry assoc-map ;  
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: correct-for-timing-overhead ( -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    *wordtimes* [ (correct-for-timing-overhead) ] change-global ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: print-word-timings ( -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    *wordtimes* get-global [ swap suffix ] { } assoc>map natural-sort reverse pprint ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-26 06:31:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: wordtimer-call ( quot -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    reset-word-timer 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    benchmark [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        correct-for-timing-overhead
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "total time:" write
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] dip pprint nl
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    print-word-timings nl ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-08 15:01:28 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-30 14:31:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: profile-vocab ( vocab quot -- )
							 | 
						
					
						
							
								
									
										
										
										
											2013-07-24 17:52:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    "annotating vocab..." print flush
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    over [ reset-vocab ] [ add-timers ] bi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    reset-word-timer
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    "executing quotation..." print flush
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    benchmark [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "resetting annotations..." print flush
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        reset-vocab
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        correct-for-timing-overhead
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "total time:" write
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] dip pprint
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    print-word-timings ; inline
							 |