Parsing text vs looping trough Array - performance question

0 favourites
  • 9 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • 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?

  • 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.

  • 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.

  • Yip, it works well. I am afriad of ' as a divider - lol

    I use | I've <-messed up too often using '

  • Yip, it works well. I am afriad of ' as a divider - lol

    I use | I've <-messed up too often using '

    ------------------------------------------------------------------------------------------------------------
    
    Items Arrays
    
    String. Parser ' /if not loading, search for missing " ' " and accidental " ` "  ","
    ------------------------------------------------------------------------------------------------------------
    [/code:2a96nc96]
    
    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.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 ...

  • 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.

  • 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.

    [attachment=0:qkpuexdw][/attachment:qkpuexdw]

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)