SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast weicool's Avatar
    Join Date
    Jul 2004
    Location
    USA
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How Expensive is String Concatenation?

    I read in the FAQ thread that string concatenation in PHP (the dot . ) is expensive. I was just wondering HOW expensive it is. I know that in Java, the String object is immutable, so concatenating Strings using the + operator will cause Strings to be first copied and then glued together. Is that the way PHP works?
    Pokemon Dream - The greatest Pokemon website of all...

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    10,000 string concatenations averages two thousandths of a second on my server. It's a non-issue, isn't it?

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    There are far more expensive things then concatenation. Please focus on those not these already beyond optimizing ideas. There is no way to make:
    PHP Code:
    $s 'data';
    $s $s ' more data'
    go any faster so stop trying. It is as fast as its going to get. (abit simplistic example)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •