;Instruction timer.

;To use this:

; 1	Comment out all the instruction between vvvvvvvv and ^^^^^^^^^^ lines
; 2	Run the program
; 3	Adjust the constant at <<<<<  until th eprogram displays 0 or very close to it
; 4     Un-comment one instruction between vvvvvvvvvv  and ^^^^^^^^^^ and run again

;The program averages 2560 executions of the selected instruction. Note that
;any single execution may more or less than the average, because the processor is
;handling interrupts all the time (timers, serial comms, LCD updates etc).

;Also, different firmware versions may give different results, because we from time to time
;change the interrupt handling. Generally we add in more stuff, like OBCB, OBQC etc, all of
;which use processor time and will tend to slow down the user program.

	On 20
	LaunchTask	TimeIt
	LaunchTask	DoIt
	RunTasksForever

xx	defByte

DoIt
;				 MMi201		MS120

;*** vvvv One instruction below here gets timed vvvvvvvv
;	YieldTask		;		74.22  excluding GoTo DoIt

; 	Pop			;140.3		62.5
;	And			;144.2		62.5
;	ON		5	;206.7		101.6
;	swap			;136.4		58.6
;	recall		xx	;163.75		74.72
;	OBLCD_SetCur	0,0	;		218.8
;	GoSub		ssss	;		128.9 with Return
;	InputFM		0	;		109.4  Not affected by argument
;	LoadX		55	;		66.6
;	OutputM		0	;		144.34  Not affected by argument
;	Input		0	;		78.12
;	dmgnz		xx,y1	;172		78
;	GoTo		Y1	;148.1		66.4
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Y1	GoTo		DoIt

ssss:	Return

InstTimer	defTIME24
CounterLo	defBYTE
CounterHi	defBYTE


TimeIt:
	STStart		InstTimer
	SetMem		CounterHi,10
TimeIt1:
	YieldTask
 	DMGNZ		CounterLo,TimeIt1
	DMGNZ		CounterHi,TimeIt1


	fSTTimeSince	InstTimer
	fLoadQ		3.90625
	fMUL
	fLoadQ		-375  ;<<<< adjust for 0 when nothing in the DoIt loop

	fAdd
	OBLCD_SetCur	0,0
	OBLCD_fDispW	8,2
	OBLCD_Text	228,"S"
	on		15
	pause	10
	off	15
	GoTo		TimeIt