Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

20
  • 130
    @nickf multiplications are trivial on modern CPUs - the string concatenation will require a lot more work! Commented Apr 19, 2011 at 19:59
  • 33
    Actually it will display time in '10:2:2' format, since it does not add an extra 0 before values below 10. Commented Oct 4, 2012 at 14:47
  • 19
    @user656925 - Multiplication involves numbers, concatenation involves strings. Computers handle numbers far more efficiently than strings. When string concatenation is done, there's a lot of memory management going on in the background. (However, if you're already doing a string concatenation anyway, then including a few extra characters in one of the strings might actually be less costly on average than the one processor op it takes to multiply two numbers together.) Commented Oct 2, 2013 at 21:31
  • 9
    @Stallman number computation is the most fundamental thing that computers do, and they're extremely efficient at it, both in memory and runtime. Brilliand's comment above is relevant, although IMHO the very final part of his comment is completely bogus. Commented Mar 19, 2016 at 11:59
  • 5
    @Stallman It's true of all languages (or nearly all, in theory an exotic language could be created that isn't like this - but all the common ones are). A string is stored internally as a pointer to a block of memory where the contents of the string are stored. The pointer itself uses the same amount of memory as most numbers do on the same system, and the memory to store the actual strings is in addition to that. Then when you concatenate the strings, you're most often creating a brand-new string with the combined contents of both strings. Commented Mar 21, 2016 at 23:32