Normal Topic GlobalValue vs. Variable (Read 990 times)
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
GlobalValue vs. Variable
Nov 12th, 2006 at 2:42pm
Print Post Print Post  
Mark,

Can you tell me if repeatedly saving to a GlobalValue in a loop, will run as fast as doing the same with a static variable?

Or, does the GlobalVariable need to be written to disk with each update?
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: GlobalValue vs. Variable
Reply #1 - Nov 12th, 2006 at 2:58pm
Print Post Print Post  
Quote:
Mark,

Can you tell me if repeatedly saving to a GlobalValue in a loop, will run as fast as doing the same with a static variable?

Or, does the GlobalVariable need to be written to disk with each update?


A Global Value is going to much slower than using a static global variable. A Global Value is a stored in your application permanently, so it must be conveyed to the application server (possibly through a network), and will be stored in the application file (.db and .dat). Additionally, because it is a keyed value, the system will have to look through the list of Global Value keys to find the matching key, which will also take time that a static global variable does need to do.

Unless the value needs to be stored with the application permanently, or needs to be communicated between forms, or between clients, you would be better served by a static global variable. A static global variable will only retaiin its value while the form is still active. Its scope is limited to the code attached to the same form, so it can't be used for inter-form communication. And it is limited to the client that ran its declaration. But because it is otherwise a normal variable, it is stored in RAM on the client, and needs no lookup of any kind. This makes it many times faster than either an element or a Global Value, probably several thousand times faster.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: GlobalValue vs. Variable
Reply #2 - Nov 12th, 2006 at 3:15pm
Print Post Print Post  
Mark,

Thank you for the extremely fast response!

I do need to use the infomation between different forms, and possibly days later. So, I ended up with a combination of static variable while running the loop (a report, actually), and then only when printing the last record, set the Global Value with what the static variable contains.

I suspected that your answer would be something like that, but I just wanted to be sure.

Thanks again.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: GlobalValue vs. Variable
Reply #3 - Nov 12th, 2006 at 3:22pm
Print Post Print Post  
Quote:
Mark,

Thank you for the extremely fast response!

I do need to use the infomation between different forms, and possibly days later. So, I ended up with a combination of static variable while running the loop (a report, actually), and then only when printing the last record, set the Global Value with what the static variable contains.

I suspected that your answer would be something like that, but I just wanted to be sure.

Thanks again.



That sounds like a wise course to take.

I ran some timing tests to see how the different means of storing information in SBasic differ in performance. All of the tests were run using Sesame 2.0 (the releative times should be about the same in Sesame 1.x.x) in Standalone mode, using a Mass Update in Customers.db. Each test is a one string write operation followed by one string read operation, and is counted as number of tests performed per second (so higher numbers are better):

Local Variable: 96,964
Static Global Variable: 61,361
Element: 28,876
GlobalValue: 751
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: GlobalValue vs. Variable
Reply #4 - Nov 12th, 2006 at 8:44pm
Print Post Print Post  
Thanks for posting the test results. That reallly drives the point home.

If there's that much difference between a local variable and a global value on a standalone, I can only imagine how much more there would be between them in client/server mode.

Something that surprises me though, is that an element is faster than a global value. I was under the impression that an element would be the slowest of all. Well, good information to know.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: GlobalValue vs. Variable
Reply #5 - Nov 12th, 2006 at 8:47pm
Print Post Print Post  
Quote:
Something that surprises me though, is that an element is faster than a global value. I was under the impression that an element would be the slowest of all. Well, good information to know.


That is because the test program writes and reads to the element, but it does not advance the element, and avoids having to talk to the server at all. Even if it did, though, it would still be faster than a global value because it does not need to do a lookup. In my test case, I put in fifty other global values to cause a reasonable lookup.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged