Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39573
| From | Martin Gregorie <martin@mydomain.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Get real, user and system time |
| Date | 2020-07-20 08:55 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <rf3m65$nl6$1@dont-email.me> (permalink) |
| References | <87o8oc99wk.fsf@munus.decebal.nl> <revnrj$115$1@dont-email.me> <5f153464$0$10264$e4fe514c@news.xs4all.nl> |
On Mon, 20 Jul 2020 08:06:31 +0200, Luuk wrote:
> On 18-7-2020 22:59, Martin Gregorie wrote:
>> On Sat, 18 Jul 2020 16:26:35 +0200, Cecil Westerhof wrote:
>>
>>> In Linux we have the time command to get the real, user and system
>>> time that a command takes.
>>> I know how to get the real time a method takes, but is there a way to
>>> get the user and system time a method takes also?
>>>
>> The only way I can think of, offhand would be the Stopwatch class,
>> which appeared here some time ago. I won't include it as the
>> (reasonably well- commented) copy I have is 118 lines. It has start(),
>> stop() methods, so start/stop should be called to time a process and
>> toString() to display the elapsed time in seconds. Its resolution is to
>> the nearest millisecond.
>>
>> I've not included it because my copy is 118 lines, tolerably commented.
>> I can e-mail you a copy if it looks useful.
>>
>>
>>
> does it looks like this class:
> https://introcs.cs.princeton.edu/java/stdlib/Stopwatch.java.html
Its a similar idea, but the version I have doesn't have a main() method
and has start(), stop() and reset() methods, IOW its better adapted to
what you're trying to do:
Stopwatch sw = new StopWatch();
...
sw.start();
myMethod(arguments);
sw.stop();
System.stderr.println("myMethod: " + sw.toString()
...
The output would be something like:
myMethod: Stopwatch(2020.07.20.09.53.56, 2020.07.20.09.53.59, 3.001
seconds)
--
Martin | martin at
Gregorie | gregorie dot org
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Get real, user and system time Cecil Westerhof <Cecil@decebal.nl> - 2020-07-18 16:26 +0200
Re: Get real, user and system time Martin Gregorie <martin@mydomain.invalid> - 2020-07-18 20:59 +0000
Re: Get real, user and system time Luuk <luuk@invalid.lan> - 2020-07-20 08:06 +0200
Re: Get real, user and system time Martin Gregorie <martin@mydomain.invalid> - 2020-07-20 08:55 +0000
Re: Get real, user and system time Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-07-21 01:40 +0200
Re: Get real, user and system time Martin Gregorie <martin@mydomain.invalid> - 2020-07-21 11:52 +0000
Threads [Was: Get real, user and system time] Eric Sosman <esosman@comcast-dot-net.invalid> - 2020-07-21 08:42 -0400
Re: Threads [Was: Get real, user and system time] Martin Gregorie <martin@mydomain.invalid> - 2020-07-21 16:55 +0000
Re: Threads [Was: Get real, user and system time] Eric Sosman <esosman@comcast-dot-net.invalid> - 2020-07-21 15:46 -0400
Re: Threads [Was: Get real, user and system time] Martin Gregorie <martin@mydomain.invalid> - 2020-07-21 20:16 +0000
Re: Threads [Was: Get real, user and system time] Martin Gregorie <martin@mydomain.invalid> - 2020-07-21 23:14 +0000
Re: Get real, user and system time Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-07-22 00:23 +0200
csiph-web