Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 26, 2011 performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
I have this small program here, which compares the call-overhead of methods from classes to structs. I guess this always has to be, because of the "polymorphism" of methods of objects. Is there something I can do to improve on the performance of methods calls with classes? please see the source here: https://gist.github.com/1242911 thanks in advance christian |
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christian Köstlin | You didn't call sw.reset() before calling sw.stop()! |
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
On 9/26/11, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> You didn't call sw.reset() before calling sw.stop()!
>
Ehh, I mean before sw.start().
|
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
In the class test reset the timer: { auto h = new HClass(); sw.reset(); // <- sw.start(); } |
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christian Köstlin | On Mon, 26 Sep 2011 14:14:09 -0400, Christian Köstlin <christian.koestlin@gmail.com> wrote:
> I have this small program here, which compares the call-overhead of methods from classes to structs. I guess this always has to be, because of the "polymorphism" of methods of objects.
>
> Is there something I can do to improve on the performance of methods calls with classes?
>
> please see the source here:
> https://gist.github.com/1242911
In addition to Andrej's information (call sw.reset()), make *sure* you compile in -release mode, because in non -release mode, all object methods are followed by a call to Object's invariant, which is never inlined! However, no invariants are called in release mode.
-Steve
|
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 09/26/2011 08:29 PM, Andrej Mitrovic wrote: > In the class test reset the timer: > { > auto h = new HClass(); > sw.reset(); //<- > sw.start(); > } thanks a lot ... i totally misused the stopwatch api. i compiled with: dmd -release -O -inline -m64 -oftarget/dmd/structs_vs_classes experimental/structs_vs_classes.d and gdc -O3 -inline -o target/gdc/structs_vs_classes experimental/structs_vs_classes.d wich resulted in: target/dmd/structs_vs_classes time with struct: 11326 for 1 time with class: 11323 for 1 and target/gdc/structs_vs_classes time with struct: 4011 for 1 time with class: 6880 for 1 which is much better than my wrong measurements... thanks for the answer!!! christian |
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christian Köstlin | Christian K.:
> i totally misused the stopwatch api.
I have misused it the same way, the first time. If other people will find the same problem then it means its API has problems.
Bye,
bearophile
|
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Mon, 26 Sep 2011 15:58:48 -0400, bearophile <bearophileHUGS@lycos.com> wrote:
> Christian K.:
>
>> i totally misused the stopwatch api.
>
> I have misused it the same way, the first time. If other people will find the same problem then it means its API has problems.
Have you ever used a real stopwatch? It works the same way :) Start/stop does not reset the time to 0, it just adds more time to the total. Reset clears to 0.
I think probably the documentation needs to be better. The example also suggests start resets the stopwatch.
-Steve
|
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christian Köstlin | On Mon, 26 Sep 2011 15:36:04 -0400, Christian Köstlin <christian.koestlin@gmail.com> wrote:
> On 09/26/2011 08:29 PM, Andrej Mitrovic wrote:
>> In the class test reset the timer:
>> {
>> auto h = new HClass();
>> sw.reset(); //<-
>> sw.start();
>> }
> thanks a lot ... i totally misused the stopwatch api.
>
> i compiled with:
> dmd -release -O -inline -m64 -oftarget/dmd/structs_vs_classes experimental/structs_vs_classes.d
> and
> gdc -O3 -inline -o target/gdc/structs_vs_classes experimental/structs_vs_classes.d
>
> wich resulted in:
> target/dmd/structs_vs_classes
> time with struct: 11326 for 1
> time with class: 11323 for 1
>
> and
> target/gdc/structs_vs_classes
> time with struct: 4011 for 1
> time with class: 6880 for 1
use -frelease to disable invariant calls on gdc.
Very important!
-Steve
|
September 26, 2011 Re: performance of structs vs classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 09/26/2011 10:30 PM, Steven Schveighoffer wrote:
> On Mon, 26 Sep 2011 15:58:48 -0400, bearophile
> <bearophileHUGS@lycos.com> wrote:
>
>> Christian K.:
>>
>>> i totally misused the stopwatch api.
>>
>> I have misused it the same way, the first time. If other people will
>> find the same problem then it means its API has problems.
>
> Have you ever used a real stopwatch? It works the same way :) Start/stop
> does not reset the time to 0, it just adds more time to the total. Reset
> clears to 0.
>
> I think probably the documentation needs to be better. The example also
> suggests start resets the stopwatch.
>
> -Steve
you are totally right ... it is the same as a real stopwatch ... so there should be no problem (i also used it correctly in another benchmark, but it was quite late and ...)
thanks
christian
|
Copyright © 1999-2021 by the D Language Foundation