1. What difference (object and sequence)
- Posted by doug edmunds <dae at WORLDACCESSNET.COM> Aug 20, 1997
- 821 views
Is there any difference (size, performance, etc.) between declaring a variable as an object and declaring it as a sequence, other than type checking? example: function F_A (object item) --do something return item end function function F_B (sequence item) --do something else return item end function --test--- sequence xxx, yyy xxx = {441, 1232, "dog", "cat"} yyy = F_A(xxx) --pass xxx back as an object, return an object yyy = F_B(xxx) -- pass xxx as a sequence, return a sequence printf(1,"\ndone\n",{})
2. Re: What difference (object and sequence)
- Posted by Eduardo Uemura Okada <cool at ART.COM.BR> Aug 20, 1997
- 813 views
Hi Doug, a variable declared as object can hold both atom values or sequences, and a variable declared as sequence can hold just sequences. Hope this helped you. Eduardo Uemura Okada e-mail: cool at art.com.br
3. Re: What difference (object and sequence)
- Posted by Daniel Berstein <danielberstein at USA.NET> Aug 21, 1997
- 809 views
- Last edited Aug 22, 1997
On 20 Aug 97 , Eduardo Uemura Okada wrote: > Hi Doug, a variable declared as object can hold both atom values or > sequences, and a variable declared as sequence can hold just sequences. ^^^^^^^^^^^^^^^^^^^^^^^^ I think your explanation isn't very acurate Eduardo: In Euphoria you have just two types of data: -Atoms (an indivisible value, such as 'A', 255 or #ff) -Sequences(kind of dinamic-flexible array, can contain either atoms of sequences) A variable declared as type object can behave as an atom or a sequence upon requirement. Example: object test test = 100 --Now test is an atom type variable test = {1,2,3,4} --Now test is a sequence! An object can't be an atom and a sequence at the same time, but a sequence element may be an atom or a sequence. Hope this little explanation helps. Regards, Daniel Berstein danielberstein at usa.net http://www.geocities.com/SiliconValley/Heights/9316
4. Re: What difference (object and sequence)
- Posted by Robert Craig <rds at CLASSIC.MSN.COM> Aug 26, 1997
- 803 views
A few days ago Doug Edmunds asked: > Is there any difference (size, performance, etc.) > between declaring a variable as an object > and declaring it as a sequence, > other than type checking? Using *very* rough numbers: 90% of the time you will see a slight (1% to 5%) improvement in speed if you declare a heavily-used variable as a sequence, rather than an object. 10% of the time you may see a very slight loss (1% to 2%). It's not something that most people should worry about. As a rule of thumb, you should declare variables using the most restrictive of the pre-defined types that you can. This will catch more bugs, make your code easier to understand, and probably make it run a few percent faster. For instance it's usually faster to declare something as an integer rather than an atom. As for memory consumption, it only matters what the current *value* of a variable is, not how it is declared. If you are serious about performance, you need to make measurements. As we saw from some postings a while back, it isn't always obvious which way of coding something is going to be faster. Even though I know how things are implemented, I am often surprised. Put small code fragments into for-loops up to a million and time them. Profile your program. Don't assume that you know which statement is the "bottleneck". For instance, most people assume that it must be faster to perform arithmetic on a whole sequence in one statement, rather than looping. This is not a good assumption. You have to measure it. There's a lot of invisible, but significant stuff going on when your program executes. Storage allocation and deallocation are important, but there are subtle hardware effects such as caching that can be very significant and hard to predict. Regards, Rob Craig Rapid Deployment Software Regards, Rob Craig Rapid Deployment Software