Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constants and SYS(5) + SYS(2003)
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00267724
Message ID:
00268716
Views:
38
>(No cheating by looking at what I say afterwards< g >).

Didn't cheat, and guessed correctly < g >

The first and last tests were idenctical (for all practical purposes). Reason being at run-time they are identical, the VFP compiler has replaced all instance of SHORT_STRING with "AAAAA", so no performance gain or loss by using a constant.

>However, if you replace the defined constant with REPLICATE("A", 5), the first instance will drop to the slowest because it's being re-evaluated on each pass.

Right, the compiler has replaced all instances of SHORT_STRING with REPLICATE("A", 5). Resulting in a decrease in performance by using a constant.

In order to gain performance the compiler would have to evaluate REPLICATE("A", 5) prior to compling, which it doesn't do.

Just for S&G, here is your test using only constants. What suprised me is this gives different results for test 2 and 3 than just the straight code.
#DEFINE SHORT_STRING       "AAAAA"
#DEFINE FOR_BEGIN 	        FOR lni = 1 TO 100000
#DEFINE FOR_END 		NEXT
#DEFINE STOP_CLOCK 		lnstop = SECONDS()
#DEFINE DISP_CLOCK 		? lnstop - lnstart
#DEFINE SHORT_VAR 		lcshort = "AAAAA"
#DEFINE START_CLOCK 	        lnstart = SECONDS()
#DEFINE TEST_1 			lcfoo = SHORT_STRING
#DEFINE TEST_2 			lcfoo = lcshort
#DEFINE TEST_3 			lcfoo = "AAAAA"

SHORT_VAR
START_CLOCK
FOR_BEGIN
	TEST_1
FOR_END
STOP_CLOCK
DISP_CLOCK
FOR_BEGIN
	TEST_2
FOR_END
STOP_CLOCK
DISP_CLOCK
FOR_BEGIN
	TEST_3
FOR_END
STOP_CLOCK
DISP_CLOCK
Roi
'MCP' Visual FoxPro

In Rome, there was a poem.
About a dog, who found two bone.
He lick the one, he lick the other.
He went pyscho, he drop dead!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform