Hi,
I try to convert some python code to D. On python I can get the cpu time for the current
process using
dcpu: float = time.process_time()
Is there some equivalent function in Phobos to get the cpu time on linux?
Kind regards
André
Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 07, 2021 Measure cpu time | ||||
---|---|---|---|---|
| ||||
Hi, I try to convert some python code to D. On python I can get the cpu time for the current
Is there some equivalent function in Phobos to get the cpu time on linux? Kind regards |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | On Friday, 7 May 2021 at 08:25:43 UTC, Andre Pany wrote: >Hi, I try to convert some python code to D. On python I can get the cpu time for the current
Is there some equivalent function in Phobos to get the cpu time on linux? Kind regards Take a look at https://code.dlang.org/packages/getr |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Imperatorn | On Friday, 7 May 2021 at 08:37:47 UTC, Imperatorn wrote: >On Friday, 7 May 2021 at 08:25:43 UTC, Andre Pany wrote: >Hi, I try to convert some python code to D. On python I can get the cpu time for the current
Is there some equivalent function in Phobos to get the cpu time on linux? Kind regards Take a look at https://code.dlang.org/packages/getr Thanks a lot :) Kind regards |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | On Friday, 7 May 2021 at 08:25:43 UTC, Andre Pany wrote: >Is there some equivalent function in Phobos to get the cpu time on linux? I don't think so, but you can use If you want to use it on Windows as well, this is a code snippet I wrote for that:
On Windows you need to link to "Psapi.lib", e.g. with |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | On Friday, 7 May 2021 at 08:52:13 UTC, Dennis wrote: >If you want to use it on Windows as well, this is a code snippet I wrote for that: For completeness, the imports it uses:
|
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | On Friday, 7 May 2021 at 08:58:33 UTC, Dennis wrote: >On Friday, 7 May 2021 at 08:52:13 UTC, Dennis wrote: >If you want to use it on Windows as well, this is a code snippet I wrote for that: For completeness, the imports it uses:
Thanks a lot. Kind regards |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | On 5/7/21 1:25 AM, Andre Pany wrote: > get the cpu time For the sake of completeness, that kind of functionality is provided by operating systems as well. For example, on Linux, it is common to run the program through 'time' to get how much wall clock advanced, how much time was spent actually executing code on the CPU, and how much time was spent by the OS itself: $ time my-program my-arguments ... Check out 'man time' to see its command line switches. ('time --help' fails to execute '--help' :) ) Ali |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | I see, https://dlang.org/phobos/core_stdc_time.html does not contain the function : "clock_gettime" Weird ... |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alain De Vos | Probably renamed ... |
May 07, 2021 Re: Measure cpu time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alain De Vos | On 5/7/21 9:46 AM, Alain De Vos wrote: > I see, > https://dlang.org/phobos/core_stdc_time.html > does not contain the function : "clock_gettime" > Weird ... stdc is about D bindings for C's std headers. I don't think clock_gettime is a standard C function. grep'ping under /usr/include/dmd reveals that clock_gettime is in this file: /usr/include/dmd/druntime/import/core/sys/posix/time.d and that is this module: module core.sys.posix.time; Ali |