Skip to content

Commit

Permalink
add performance tip on string interpolation. closes #2050
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 16, 2014
1 parent ea10a0b commit 321e7fe
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/manual/performance-tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,30 @@ Taken to its extreme, pre-allocation can make your code uglier, so
performance measurements and some judgment may be required.


Avoid string interpolation for I/O
----------------------------------

When writing data to a file (or other I/O device), forming extra
intermediate strings is a source of overhead. Instead of::

println(file, "$a $b")

use::

println(file, a, " ", b)

The first version of the code forms a string, then writes it
to the file, while the second version writes values directly
to the file. Also notice that in some cases string interpolation can
be harder to read. Consider::

println(file, "$(f(a))$(f(b))")

versus::

println(file, f(a), f(b))


Fix deprecation warnings
------------------------

Expand Down

0 comments on commit 321e7fe

Please sign in to comment.