Passing array as const slows down code?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Apr 30 07:03:32 PDT 2012
On Fri, 27 Apr 2012 20:03:48 -0400, Joseph Rushton Wakeling
<joseph.wakeling at webdrake.net> wrote:
> On 28/04/12 00:29, Era Scarecrow wrote:
>> Last try adding ref after const; At the off chance it's shallow
>> copying, this
>> should remove that.
>
> Ahhh, that works. Thank you!
>
> Back story: originally the reputation() function just took the array
> ratings and made an internal copy, ratings_, which was used by the rest
> of the code. I took that out in this commit:
> https://github.com/WebDrake/Dregs/commit/4d2a8a055321c2981a453fc4d82fb781da2ea5c7
>
> ... because I found I got about a 2s speedup. It's exactly the speedup
> which was removed by adding "const" to the function input, so I presume
> it's as you say, that this was implicitly creating a local copy.
Try removing the ref and see if it goes back. That usage of ref should
not affect anything (if anything it should be slower, since it's an extra
level of indirection).
There is no implicit local copy for const. I have a suspicion that you
changed two things and forgot about one of them when running your tests.
-Steve
More information about the Digitalmars-d-learn
mailing list