Parsing text vs looping trough Array - performance question

Discussion and feedback on Construct 2

Post » Mon Apr 14, 2014 1:00 am

Hi,

What is more performance efficient - parsing trough text or looping trough array fields, in search for specific part of data - or it doesn't really matter?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Mon Apr 14, 2014 6:56 am

It shouldn't really matter.
I would say array is the better option, less chances of error in finding what you want. And probably marginally faster depending how you plan to parse your text. If you are talking a small little chunk of text then go that way. If you talking 50 plus entries, and especially in the 100's, 1000's then array were designed for that.

I still parse text that i fetch from an array(array within an array - lol), maybe that is an option.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Apr 14, 2014 1:49 pm

DUTOIT wrote:It shouldn't really matter.
I would say array is the better option, less chances of error in finding what you want. And probably marginally faster depending how you plan to parse your text. If you are talking a small little chunk of text then go that way. If you talking 50 plus entries, and especially in the 100's, 1000's then array were designed for that.

I still parse text that i fetch from an array(array within an array - lol), maybe that is an option.


We're doing exactly same thing.
[["Mace'Mele'60'50'30'30'200'A mace"]]

Finding that faster to write, then if it would be in separated array fields. But in separated array fields it is easier to read and the conditions end up being shorter. Thought something could convince me to change the way I'm doing it right now. :D
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Mon Apr 14, 2014 2:39 pm

Yip, it works well. I am afriad of ' as a divider - lol
I use | I've <-messed up too often using '
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Mon Apr 14, 2014 2:44 pm

DUTOIT wrote:Yip, it works well. I am afriad of ' as a divider - lol
I use | I've <-messed up too often using '


Code: Select all
------------------------------------------------------------------------------------------------------------

Items Arrays

String. Parser ' /if not loading, search for missing " ' " and accidental " ` "  ","
------------------------------------------------------------------------------------------------------------


:D

I use || when parsing trough Arrays files. I also use _ to parse between A'B_

Although maybe it's the uk kb im using but ' is just above my right shift so it's not problematic.
Last edited by megatronx on Mon Apr 14, 2014 2:50 pm, edited 2 times in total.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Mon Apr 14, 2014 2:48 pm

Depends on what you need. If this is an occasional search. Then just stick with parsing text. However if this is action you need to do per tick. Then turn your text into an array by parsing the string at least once.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028

Post » Mon Apr 14, 2014 2:52 pm

jayderyu wrote:Depends on what you need. If this is an occasional search. Then just stick with parsing text. However if this is action you need to do per tick. Then turn your text into an array by parsing the string at least once.


I see. Yes it is an action to do per tick. So you're saying that there is a performance difference between those two?

EDIT: let me elaborate. So I have array with Items in it like this one [["Mace'Mele'60'50'30'30'200'A mace"]], and then when my character is attacking, function is being called to check what weapon he has, and then acts accordingly, parsing trough this line of text to get the data... hmm so now when I'm thinking about it it is not per tick... hmmm... I might need to take a day off ...
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Mon Apr 14, 2014 3:04 pm

Depends on how your parsing. I suspect your tokenating. So every time you tokenate the search begins back at 0. If you tokenate your self by actively tracking your current character position. compare until next comma then you can save time. But otherwise your going to lose performance.

So as an example
mega, super, fun happy, time

If you for some reason need time
while(word != "time")
word = tokenate( srtring, loopindex, ",")

**** let's ignore the permanent stuck loop this would require.
anyway this would search through your string 5 times to find time. What the system has to do is create a string for eaching parsing into a word. So the system is going to create an array every tick. then destroy the array. So your asking for an array to be created an destroyed.

Where as if you broke it into an array at the start of layout you could just do
array.find("time")
and then avoid creating a tokenized array at the beginning of the layout.

now however if you instead did
if( string.find("time") )
then that would be faster than tokenized parsing.






Where as in an array. once you compare the first you move on to the second.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028

Post » Mon Apr 14, 2014 3:16 pm

jayderyu wrote:Depends on how your parsing. I suspect your tokenating. So every time you tokenate the search begins back at 0. If you tokenate your self by actively tracking your current character position. compare until next comma then you can save time. But otherwise your going to lose performance.

So as an example
mega, super, fun happy, time

If you for some reason need time
while(word != "time")
word = tokenate( srtring, loopindex, ",")

**** let's ignore the permanent stuck loop this would require.
anyway this would search through your string 5 times to find time. What the system has to do is create a string for eaching parsing into a word. So the system is going to create an array every tick. then destroy the array. So your asking for an array to be created an destroyed.

Where as if you broke it into an array at the start of layout you could just do
array.find("time")
and then avoid creating a tokenized array at the beginning of the layout.

now however if you instead did
if( string.find("time") )
then that would be faster than tokenized parsing.

Where as in an array. once you compare the first you move on to the second.


Ok, working on understanding it. Let me show you what I have, and you'll let me know what you think about it. This part is being called on function.
code.jpg
You do not have the required permissions to view the files attached to this post.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099


Return to Construct 2 General

Who is online

Users browsing this forum: AnimH01 and 14 guests