NEWS ARTICLES


    What's News in the PlayBasic world ? - Find out here.



 PlayBasic V1.64NO Upgrade Work in Progress

By: Kevin Picone Added: February 16th, 2013

Category: All,Upgrade,Beta Testing

    PlayBasic V1.64O Beta1 - Dynamic Function Calling
     While under the hood, figured I'd tweak the searching up a little more in the CallFunction operation. If you call a function by name, then it has to search through the function names looking for a match. The search it self is nothing fancy, it's just a linear search, so figured it'd be a handy place for a hash level pre-screen. With the hash, V1.64O it's about 40% quicker than V1.64N3 using the original bench mark code.

PlayBasic Code:
 Print "Dynamic Psub Calling With Parameter"

	Dim FunctionNames$(3)
	Dim FunctionIndexes(3)

	FunctionNames$(0)="Test0"
	FunctionNames$(1)="Test1"
	FunctionNames$(2)="Test2"
	FunctionNames$(3)="Test3"

	FunctionIndexes(0)=FunctionIndex("Test0")
	FunctionIndexes(1)=FunctionIndex("Test1")
	FunctionIndexes(2)=FunctionIndex("Test2")
	FunctionIndexes(3)=FunctionIndex("Test3")
	
	
	Global Value0
	Global Value1
	Global Value2
	Global Value3

	MaxTests=10000

	Do
		Cls 0
		
			frames++

			t=timer()
				for lp=0 to MaxTests-1
				   CallFunction FunctionNames$(lp &3),lp
			   next
			tt1#+=(timer()-t)
			print tt1#/frames
			print "tests:"+STR$(lp)
		   
			t=timer()
				for lp=0 to MaxTests-1
				   CallFunction FunctionIndexes(lp &3),lp
			   next
			tt2#+=(timer()-t)
			print tt2#/frames
			print "tests:"+STR$(lp)

			print fps()
			print Value0	
			print Value1	
			print Value2
			print Value3	


		Sync
	loop
	



Psub Test0(a)
		Value0++
EndPsub 

Psub Test1(a)
		Value1++
EndPsub 

Psub Test2(a)
		Value2++
EndPsub 

Psub Test3(a)
		Value3++
EndPsub 


COMMANDS USED: PRINT | DIM | CLS | TIMER | STR$ | FPS | SYNC |


Update:

     Updated the search routine again, stripping another 5->6 milliseconds from the earlier update. I'd still strongly encourage user to pre-compute the function index prior, rather than dynamically searching for the function name (as a string) every single time. But it's viable either way.

PlayBasic V1.64O Beta2 - Small Tweaks

     Add a couple of tiny tidbits into today's build, the first is a constant to return the current Optimizer state. (PBOptimizeState), which allows a include to set the optimizer state it wants/requires without changing the state for the rest of the program. To do that, you just preserve the state in constant on entry to the code block then restore it at the end.

PlayBasic Code:
	; remember the current optimizer state	
	COnstant PreServeOptimizeMode = PbOptimizeState
	

	; Enable Type Caching and general optimizations	
	OptExpressions 3

	; print Optimizer stat within this block of code		
	print PbOptimizeState

     
	; restore it at the end of this block of code
	OptExpressions PreServeOptimizeMode


	; print the optimizer state here
	print PbOptimizeState


	Sync
	waitkey


COMMANDS USED: OPTEXPRESSIONS | PRINT | SYNC | WAITKEY |


     64bit Start Interval / End Interval (High Resolution timing)

     Dropped a couple of functions in to query the number of high res ticks between the pair of calls. The first call stamps the start time, and the End call gets the number of the ticks that has past since the start call. Internally the timer resolution is 64bit, so the routine returns the interval in 32bit. On my system the high res timer is about 1000 ticks the resolution of the milliseconds. It'll actually be different for different CPU's... But ya get that..

     The Functions use an internal array for storing up to 128 (at this time) unique time points. Will most likely reduce that to 32 or something. The high resolution time is just like the millisecond timer, it's counting up regardless of what app is currently being executed.

PlayBasic Code:
	Max=25000

Do	
	cls
	
	frames++


	; Set the starting time, so we can time the number of hi
	; resolution ticks between the pair of calls
	StartInterval(0)	

	; get the current millisecond when the loop starts
	timeStart=timer()

	; do a loop for something to time
	For lp =0 to Max
			a=b
	next

	; get the number of low res / milliseconds that haver past
	Time1=Timer()-TimeStart

	; get the high resolution of ticks that have past
	time2=EndInterval(0)	

	tt1#+=Time1
	tt2#+=Time2

	print "      Average Ticks:"+str$(tt1#/frames)
	print "Average Hires Ticks:"+str$(tt2#/frames)
		
	sync
loop	


COMMANDS USED: CLS | TIMER | PRINT | STR$ | SYNC |


    PlayBasic V1.64O Beta3 - String Fixes

     Dunno how long this one been hanging around, but looking at the source i'd say forever. Anyway today's little issue was found in the CutRight$() function, when the cut point is less than the first character. Previously it'd return the entire string, now it returns a null string like it should. I suspect the same fault occurs with cut left also. Assuming they're cut and paste of each other..

PlayBasic Code:
	s$="PlayBasic"
	
	print "CutRight$"
	for lp =0 to len(s$)+10
			print str$(lp)+CutRight$(s$,lp)
	next
	print ""
	print ""
	print ""

	print "CutLEft$"
	
	for lp =0 to len(s$)+10
			print str$(lp)+CutLeft$(s$,lp)
	next
	
	print ""
	print ""
	print ""

	Sync
	waitkey
	

COMMANDS USED: PRINT | LEN | STR$ | CUTRIGHT$ | CUTLEFT$ | SYNC | WAITKEY |


    Read Blog

Read PlayBasic V1.64O development blog







 

 
     
 
       

(c) Copyright 2002 / 2024 Kevin Picone , UnderwareDesign.com  - Privacy Policy   Site: V0.99a [Alpha]