Re: String concatenation performance



"Java script Dude" <despam2004@xxxxxxxx> wrote in message
news:1127179763.114331.8620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> In many languages, it is necessary to string together multiple strings
> into one string for use over multiple lines of code.
>
> Which one is the most efficient from the interpreters perspective:

With samples this small I doubt you could ever measure a difference even on
a slow computer.

You could try to discover a difference by:

1) Creating much larger samples.

This can be informative but isn't conclusive. Many interperters are
otpimized for "real world" information: performance often doesn't scale
regularly as you increase the size of the data being worked with.

2) Running the sample many times via an internal loop.

The idea here is to write a JavaScript program that loops over your code
many, many times until a difference can be measured.

This can also be informative but again isn't conclusive. When you start
doing tasks large numbers of times you get into performance issues that may
not be associated with the task at hand: loop efficiency, memory leaks, etc.

3) Running the sample many times via an external loop.

The idea here to run the sample many times using some external manager.
You'd do this to try and measure the "real" code, not an artificial version
of it.

However this also has some issues. Namely the fact that the code is running
in a container and that container is using system resources along with the
process that's managing the test. The container may have issues with
repeated accesses (opening the same web page again and again and again in a
browser, for example, often results in increased memory usage).

Lastly you're talking about JavaScript... but "JavaScript" doesn't define an
interpreter, it's a spec. What's fast in one implementation may be dog slow
in another. So any tests you construct really have to be implementation
specific.

I would plan to do multiple examples of each kind of test I mentioned (and
perhaps others) and attempt to collate the results into something useful.
You'd have to run the tests many, many times (switching the order of the
testing) to ensure that the external resource consumption issues are
minimized as much as possible.

I don't have an answer to your question, I'm afraid... but it would neat to
figure out. However in the end my gut (and if you'd seen my gut you'd know
it's not something you can easily ignore) says that in any real-world
application the difference will be negligible. My general advice is to
build what's easiest to understand and maintain first - then IF there's a
performance issue, find some places to tighten up.

(Sorry - I didn't plan to veer off on a lecture there... the question is
definitely interesting. I tend to rattle on when I'm interested.)

Jim Davis


.



Relevant Pages

  • Re: subprocess.Popen - file like object from stdout=PIPE
    ... EQ_output is a string containing multiple lines. ... I'd prefer a file-like object, ... so that I can loop over the lines of it like ...
    (comp.lang.python)
  • Re: loop question
    ... explain is I am assigning multiple $strings to multiple arrays, ... If looking what you written here, you want a variable, not an arrya, that has a numerical value which increases for each loop ... stupidstring0, stupidstring1 to stupidstring9, all containing the value "stupid string". ...
    (alt.php)
  • Re: String concatenation performance
    ... into one string for use over multiple lines of code. ... takes less code to write but I'm not sure how effective it is when it reaches the language optimization and interpreter. ... Put both cases in a for..loop with a timer and loop them both about ...
    (comp.lang.javascript)
  • extension_pack
    ... It is used to set upper loop -- limits for non-deterministic values thus avoiding the use of access -- types and enabling the functions to be used for synthesizeable code. ... DivisorVal: integer) return std_logic_vector; function "/"(DividendVal: string; DivisorVal: integer) return std_logic_vector; ... for loopVar in 0 to slvVal'length/4-1 loop ... end loop; if then return not resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to else return resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to end if; ...
    (comp.lang.vhdl)
  • extension_pack
    ... It is used to set upper loop -- limits for non-deterministic values thus avoiding the use of access -- types and enabling the functions to be used for synthesizeable code. ... DivisorVal: integer) return std_logic_vector; function "/"(DividendVal: string; DivisorVal: integer) return std_logic_vector; ... for loopVar in 0 to slvVal'length/4-1 loop ... end loop; if then return not resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to else return resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to end if; ...
    (comp.lang.vhdl)

Loading