It is currently Thu May 23, 2013 5:49 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 61 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
 Post subject: simple speed optimization request
PostPosted: Wed Jan 11, 2012 4:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
Fred/Freak,
For execution speed sake, please make this feature (described in Help) optional:
"If you don't assign an initial value to the variable, their value will be 0. "

For each variable, that feature requires an individual "Push 0", whereas by making it optional it would require only adding a single number to the stack pointer.

Thanks.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 4:38 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 8875
Location: France
The problem to this "speed" improvement is all your variables and structures will be left uninitialized, and believe me, it will leads to very hard to find bugs. IHMO the extra push are not a perf killer.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 5:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
But with a user-selectable option, anybody enabling it will be aware of it. I, personally, NEVER count on the compiler to initialize anything, just out of good programming practice.

For those of us who use many small procedures, these push/pop combinations are a significant percentage of code.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 6:01 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 8875
Location: France
There is no POP ;). Anyway, in PB all is 0 initialised, and i think it's good to leave the same assumption for eveyone.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 7:28 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1716
Macros can be used to replace "many small procedures"...


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 7:54 pm 
Offline
Addict
Addict

Joined: Tue May 06, 2003 5:07 pm
Posts: 2257
Location: UK
This is something I love about PB, please leave it the way it is :)


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 8:39 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 26, 2009 3:51 pm
Posts: 194
Location: Westernmost tip of Norway
Polo wrote:
please leave it the way it is :)

+1 :wink:

_________________
You never learn anything by doing it right.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Wed Jan 11, 2012 11:40 pm 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1459
KJ67 wrote:
Polo wrote:
please leave it the way it is :)

+1 :wink:

+1

_________________
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 2:03 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
Isn't this why we have an OPTIONS dialog box??? Because we don't all like it identical?


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 2:03 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
Michael Vogel wrote:
Macros can be used to replace "many small procedures"...

Not so easy to debug.

Especially with recursion.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 7:08 am 
Offline
Addict
Addict

Joined: Sun Aug 08, 2004 5:21 am
Posts: 1085
Location: Netherlands
You can use Static variables.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 9:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 21, 2011 8:25 am
Posts: 549
wilbert wrote:
You can use Static variables.


That's not a solution.
While it's true that this can cause problems and bugs that are hard to find,
modern compilers are able to issue a warning when a variable is being used
that has not been initialized which (almost) nullifies those issues.

So I'm with Tenaja on this, I'd welcome this feature as a compiler option.

_________________
Image
ImageImageImage
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 10:10 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1716
Statics also do some initializing code, so let's go global... :mrgreen:
Code:
Global a

Procedure test()
   
   ;Static a
   
   Debug a
   a+1
   
EndProcedure

a=99
test()
test()
Debug a


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 1:05 pm 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
Honestly, initializing them manually is a bigger performance hit than initializing them automatically.

The last time I checked, static didn't do any initialization when the procedure is called. The default value for a static variable is set at compile time.

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject: Re: simple speed optimization request
PostPosted: Thu Jan 12, 2012 4:03 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
To both Wilbert and Michael V, apparently you both missed my previous post, as both of your options nullify the benefits and the point of recursion.

Trond wrote:
Honestly, initializing them manually is a bigger performance hit than initializing them automatically.

Trond, this may be true if you do a lot of For x=0 to 9 loops. However, in one of my 7500+ lines files, I just counted and I have fewer than 70 "= 0" assignments, and I NEVER trust the compiler to initialize them to zero, so this includes all of my For x=0 loops, as well as every define-time initialization.

In fact, this post made me realize that the problem is worse than I thought! This code:
Protected a = 0, b = 0, c = 1

compiles to this:
Code:
  XOR    eax,eax
  PUSH   eax
  PUSH   eax
  PUSH   eax                                                                                                                                                                                                       
; Protected a = 0, b = 0, c = 1
  MOV    dword [esp],0
  MOV    dword [esp+4],0
  MOV    dword [esp+8],1

So even though the compiler "initializes" to zero (using the push, as I was aware), it behaves as if the compiler itself is unaware of the initialization! In essence, good programming practice of initializing your own variables produces WORSE output!

This is the preferred output:
Code:
add esp, #8      ; or whatever the syntax is...
  MOV    dword [esp],0
  MOV    dword [esp+4],0
  MOV    dword [esp+8],1


Because then, when I do NOT initialize them at definition (the norm, since they are usually set at first use), a whole slew of variables (8 in this case) can be allocated like this:
add esp, #24

I do appreciate that at least the compiler uses a loop to initialize large amounts (for smaller output)...however, that consumes even MORE time per variable.

; ------------------------------------------------------
I understand some people will not appreciate the improvement realized within the request. Nevertheless, it can make a difference in both output size (minor) and speed of execution (major) when numerous procedures are called recursively (or repetitively). Plus, it will avoid the "penalty" for coding with the good programming practice of initializing your own variables. And in reality, I must continue to initialize the vars manually myself... afterall, I need the code to read as if the compiler does not, in case I ever port it to another compiler that does not.

I would appreciate if this option is implemented. I understand, Fred, that you have many requests, and I do appreciate you taking the time to consider this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 61 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye