SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to read inputs with minimal delay

    ok basically im building a script that reads input and have to "make meaning" or the input. now basically im not worried about how to do the implementation, but im worried about how slow or how fast the script may run if i choose the wrong method. which would be preferred?:

    1. read chars 1 by 1
    2. Split that string into multiple sections, which are furthur split into more sections.
    3. a combination of the 2?

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I would think that simply reading the value of a field as a whole string would be the fastest method.

    You can use the native String method in JavaScript .charAt() to read a particular character in the string (and thus you can use it to iterate over the string and check each individual character).

    Do you perhaps have an example / use case to better illustrate your problem?
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    erm not really. im using the charAt right now, but im worried if there is any performance issues with charAt when the string gets v long. say 15000 chars

  4. #4
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    If your input expectations are that long, is it really necessary to re-interpret the string character-by-character?

    What you're actually going to do with the string once you've read it will affect performance more than the actual string reading.

    Performance is also heavily dependent on the browser you're testing in. For example, a simple array.push() on 1,000,000 characters read in using charAt() in a for look will take approximately 30ms in Chrome, but can take up to 1400ms in IE8 (and about 450ms in Fx 3.6).

    Could you perhaps give a use case of how you would need to interpret the string, what sort of things need to be done to it to "make meaning" out of it?
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •