Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 4 of 4

This is a discussion on Comparison of speed for some string functions in Chrome within the Plugins Development section, part of the Chrome Plugins category: Some remark: Replace: .replace(from, to) - 65ms .split(from).join(to) - 200ms array creating is not very fast. Work with comma separated ...


  1. #1
    Lex1 is offline Member
    Join Date
    Jan 2009
    Posts
    67

    Default Comparison of speed for some string functions in Chrome

    Some remark:

    Replace:
    .replace(from, to) - 65ms
    .split(from).join(to) - 200ms

    array creating is not very fast.

    Work with comma separated value:
    var a = b.split(','); for(var i = 0; i < a.length; i++){} - 147ms
    b.replace(/[^,]+/g, function(s){}) - 235ms

    But lambda expression is even worse.

    Replace for the first occurrence
    .replace(/s/, '') - 29ms
    .replace('s', '') - 34ms

    Maybe because every time called toString

    Substring:
    .slice - 28ms
    .substr - 30ms

    slice seems as better choice for string reduction.

    Trim:
    .replace(/^\s+|\s+$/g, '') - 64ms
    .replace(/^\s+/, '').replace(/\s+$/, '') - 82ms

    Get symbol from string
    str[1] - 14ms
    str.charAt(1) - 16ms

    ...
    Last edited by Lex1; 10-02-2009 at 08:26 AM.

  2. #2
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Cool. :] Good to know.
    I've never really used slice much.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  3. #3
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    Usefull, thanks for that.

  4. #4
    deVars's Avatar
    deVars is offline Member
    Join Date
    Oct 2009
    Posts
    44

    Default

    What surprise me was the call to replace using regex was faster than using string.
    29ms vs 34ms!
    Lead me not into temptation,
    I already know the way.

Similar Threads

  1. Replies: 3
    Last Post: 09-10-2009, 05:32 PM
  2. Latest Chrome loosing speed dials
    By Michael3185 in forum Chrome Troubleshooting
    Replies: 10
    Last Post: 08-06-2009, 11:56 PM
  3. How can I add a search string?
    By Glennie in forum Chrome Tips & Tricks
    Replies: 2
    Last Post: 07-15-2009, 09:12 PM
  4. Safari 4 beats Chrome on speed tests
    By Stamga in forum General Chat
    Replies: 3
    Last Post: 04-06-2009, 08:39 PM
  5. Google Chrome speed?
    By Chrome Fanatic in forum Chrome Talk
    Replies: 1
    Last Post: 03-09-2009, 12:11 AM

Posting Permissions

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