Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)

by Anonymous Monk
on Sep 08, 2008 at 22:21 UTC ( [id://709899]=note: print w/replies, xml ) Need Help??


in reply to Re: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
in thread Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

It’s not about it being faster but more efficient. Each time you concatenate strings you cause new copies of the original string variable to be made.
  • Comment on Re^2: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)

Replies are listed 'Best First'.
Re^3: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by fergal (Chaplain) on Sep 29, 2008 at 17:55 UTC

    So since faster is a relatively objective term and "efficient" depends on what you're trying to minimise usage of, arguing that it's more efficient without further details doesn't really work.

    Of course you could define efficiency differently. Maybe you're trying to minimise peak memory consumption, network utilisation, coding time or whatever but you haven't said that's what you want.

    In this case, why do you want to avoid the string copying? Because each copy takes time. Unless the final string is long enough to start filling main memory, memory usage is not an issue and that leaves only speed. So as far as I can see, except for special cases, when discussing string concat the only useful definition of "more efficient" == "faster".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://709899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found