digitalmars.D.learn - performance of structs vs classes
- =?ISO-8859-1?Q?Christian_K=F6stlin?= (9/9) Sep 26 2011 I have this small program here, which compares the call-overhead of
- Andrej Mitrovic (1/1) Sep 26 2011 You didn't call sw.reset() before calling sw.stop()!
- Andrej Mitrovic (2/3) Sep 26 2011 Ehh, I mean before sw.start().
- Andrej Mitrovic (6/6) Sep 26 2011 In the class test reset the timer:
- =?ISO-8859-1?Q?Christian_K=F6stlin?= (19/25) Sep 26 2011 thanks a lot ... i totally misused the stopwatch api.
- bearophile (4/5) Sep 26 2011 I have misused it the same way, the first time. If other people will fin...
- Steven Schveighoffer (8/12) Sep 26 2011 Have you ever used a real stopwatch? It works the same way :) Start/st...
- =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= (6/20) Sep 26 2011 you are totally right ... it is the same as a real stopwatch ... so
- Steven Schveighoffer (5/27) Sep 26 2011 use -frelease to disable invariant calls on gdc.
- =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= (4/34) Sep 26 2011 you are right ... this leads to 6183 for gdc with class
- Steven Schveighoffer (10/17) Sep 26 2011 e =
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
Sep 26 2011
You didn't call sw.reset() before calling sw.stop()!
Sep 26 2011
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().
Sep 26 2011
In the class test reset the timer: { auto h = new HClass(); sw.reset(); // <- sw.start(); }
Sep 26 2011
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
Sep 26 2011
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
Sep 26 2011
On Mon, 26 Sep 2011 15:58:48 -0400, bearophile <bearophileHUGS lycos.com> wrote:Christian K.: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. -Stevei 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.
Sep 26 2011
On 09/26/2011 10:30 PM, Steven Schveighoffer wrote:On Mon, 26 Sep 2011 15:58:48 -0400, bearophile <bearophileHUGS lycos.com> wrote: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 christianChristian K.: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. -Stevei 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.
Sep 26 2011
On Mon, 26 Sep 2011 15:36:04 -0400, Christian K=C3=B6stlin = <christian.koestlin gmail.com> wrote:On 09/26/2011 08:29 PM, Andrej Mitrovic wrote:In the class test reset the timer: { auto h =3D 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 1use -frelease to disable invariant calls on gdc. Very important! -Steve
Sep 26 2011
On 09/26/2011 10:34 PM, Steven Schveighoffer wrote:On Mon, 26 Sep 2011 15:36:04 -0400, Christian Köstlin <christian.koestlin gmail.com> wrote:you are right ... this leads to 6183 for gdc with class thanks! christianOn 09/26/2011 08:29 PM, Andrej Mitrovic wrote:use -frelease to disable invariant calls on gdc. Very important! -SteveIn 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
Sep 26 2011
On Mon, 26 Sep 2011 14:14:09 -0400, Christian K=C3=B6stlin = <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, becaus=e =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/1242911In addition to Andrej's information (call sw.reset()), make *sure* you = = compile in -release mode, because in non -release mode, all object metho= ds = are followed by a call to Object's invariant, which is never inlined! = However, no invariants are called in release mode. -Steve
Sep 26 2011