Speed: Logical statments vs character manipulation
by George Anderson · in Torque Developer Network · 05/30/2010 (4:37 pm) · 3 replies
I'm wondering if any one knows any good resourses that can tell me what would be faster.
Lets say I have a comma delimited string and each comma seperates a value.
Then I was going to use character manipulation to split those values out of storage and then perform some processes to determine the attributes of the process, (damage speed type of attack all that jazz).
At this point I'm thinkin it should be that most times it has 10 values but can range from 6 to 16ish.
The blocks if it was split would probably be 6,10 (common) and greater than 10(uncommon).
Now would it be faster to pull these values out, store them in variables and run a comparison against them all even though most of them are "default"?
OR
case the count of values (of course assigning them in the correct order to seperate different types of attacks would be important) to determine roughly how to process them and then send them to more specialized comparisons that would use less memory?
Lets assume that the server that is running them is pretty powerful.
Lets say I have a comma delimited string and each comma seperates a value.
Then I was going to use character manipulation to split those values out of storage and then perform some processes to determine the attributes of the process, (damage speed type of attack all that jazz).
At this point I'm thinkin it should be that most times it has 10 values but can range from 6 to 16ish.
The blocks if it was split would probably be 6,10 (common) and greater than 10(uncommon).
Now would it be faster to pull these values out, store them in variables and run a comparison against them all even though most of them are "default"?
OR
case the count of values (of course assigning them in the correct order to seperate different types of attacks would be important) to determine roughly how to process them and then send them to more specialized comparisons that would use less memory?
Lets assume that the server that is running them is pretty powerful.
#2
---Explanation of the two processes I am asking about----
Option one is string manipulation so it has to find the start and end of the word then pull that word(or number) in to a memory allocation. Then do a comparison against another value that it has stored. It has to do this for each word in the string and the String would have 16 values even if most of them are default or empty.
Or
I could start by examining how many words there are before sending the string to a function. So, it wouldn't have to process a bunch of empty values.
---the Questsion is here---
What is faster, striping and comparing 4 to 10 extra default values, or evaluating an extra logical step(probably a case statment comparing the wordcount)?
I'm thinking that the second option should be faster but was hoping some one had some real world experiance or a good website with optimization techniques that fit the situation.
05/31/2010 (1:55 pm)
I was thinking of this as a generic question since its more of a programming question than a product specific question.---Explanation of the two processes I am asking about----
Option one is string manipulation so it has to find the start and end of the word then pull that word(or number) in to a memory allocation. Then do a comparison against another value that it has stored. It has to do this for each word in the string and the String would have 16 values even if most of them are default or empty.
Or
I could start by examining how many words there are before sending the string to a function. So, it wouldn't have to process a bunch of empty values.
---the Questsion is here---
What is faster, striping and comparing 4 to 10 extra default values, or evaluating an extra logical step(probably a case statment comparing the wordcount)?
I'm thinking that the second option should be faster but was hoping some one had some real world experiance or a good website with optimization techniques that fit the situation.
#3
Sorta like:
%ScriptObject.DATANAME = THE DATA YOU WANT
%RedFish.FishSize = 42;
%RedFish.FishName = "Nemo";
%NOWfish.ThisFishName = %RedFish.FishName;
%NOWfish.ThisFishSize = %RedFish.FishSize;
See if you can find any helpful information from here:
www.torquepowered.com/search?q=ScriptObject+&x=18&y=13
EDIT: local lighting storm required me to put more hast then thought into this reply, oversights have now been corrected (And my electrical power did not fail).
05/31/2010 (2:32 pm)
Myself would use an ScriptObject to store the data and then simply pick out and compare the data, based on the idea that one object is a container for the data and you use that container to load another object with the data you need to manipulate.Sorta like:
%ScriptObject.DATANAME = THE DATA YOU WANT
%RedFish.FishSize = 42;
%RedFish.FishName = "Nemo";
%NOWfish.ThisFishName = %RedFish.FishName;
%NOWfish.ThisFishSize = %RedFish.FishSize;
See if you can find any helpful information from here:
www.torquepowered.com/search?q=ScriptObject+&x=18&y=13
EDIT: local lighting storm required me to put more hast then thought into this reply, oversights have now been corrected (And my electrical power did not fail).
Torque 3D Owner Caylo Gypsyblood
If I am understanding this correctly, option number one is the answer to -what exactly is your question?
But i do not think either of them are the optimal method to tackle what i think your trying to do from the convoluted example details you provide. But i must confess i am of the lifeform type who can not read other peoples minds so I am inadequate to truly offer better support, without deeper details to go by..
And I myself always assume 'that the server that is running them is pretty powerful.' But in my case 'them' is actually a legion of enslaved hamsters, who i fear will someday use that powerful server against me.