Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - as we are talking about speed again...

as we are talking about speed again...

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Eric on Tue Apr 03, 2001 12:23 pm

hi.
i just checked back in after quite a while and found the new version - offering a switch! sounds great, so i tried to test it (code below) against using a function-pointer array, like mentioned in the knowledge base. on my palm it says:

switch: 258
array: 195

i wonder if i can test it this way. if so, someone might be interested in this outcome...

if not: im interested in how to do better...


eric



//Switch Test
int x,y,t,z;

pointer f[4]; //function pointers to be

f0 () { z++; } //identical functions
f1 () { z++; } //as in the switch
f2 () { z++; }
f3 () { z++; }

main () {
f[0]=&f0;
f[1]=&f1;
f[2]=&f2;
f[3]=&f3;

z=0;
x=1000;
y=1;

t=ticks();
while (x--) {
switch(y) {
case 1: z++;
break;
case 2: z++;
break;
case 3: z++;
break;

default: z++;
}//switch y
y=random(3);
}//while x
t=ticks()-t;
puts("switch: "+t+"\n");

z=0;
x=1000;
y=1;
t=ticks();
while (x--) {
f[y];
y=random(3);
}//while x
t=ticks()-t;
puts("array: "+t+"\n");
}
Eric
 
Posts: 7
Joined: Sun Dec 10, 2000 1:00 pm
Location: Germany

Postby jstadolnik on Wed Apr 04, 2001 12:18 am

Actually, the switch is faster. You have some coding mistakes:

1) The z variable is not getting incremented in the second "array" case because "f[y];" is not calling the function. You need to do "(*f[y])();".

2) random(x) returns a value from 0 to x-1. The switch is thus not hitting all the cases (though this is probabably not effecting performance).

Joe
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby Thad on Wed Apr 04, 2001 7:07 am

In addition to jstadolnik's comments I'd like to add that the switch statement has to do extra work for the default case.

Using the function table approach does not hanldle cases outside the array, nor does it handle situations where the values used to switch are non contiguose.

Thad
Thad
Thad
 
Posts: 33
Joined: Thu Feb 22, 2001 10:27 am
Location: United Kingdom

Postby Eric on Wed Apr 04, 2001 1:31 pm

i see. didnt think about it. thanks,

eric
Eric
 
Posts: 7
Joined: Sun Dec 10, 2000 1:00 pm
Location: Germany


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 0 guests

cron