Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Get real, user and system time Date: Mon, 20 Jul 2020 08:55:33 -0000 (UTC) Organization: A noiseless patient Spider Lines: 48 Message-ID: References: <87o8oc99wk.fsf@munus.decebal.nl> <5f153464$0$10264$e4fe514c@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 20 Jul 2020 08:55:33 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="3637c02917ce4e31b5f720adff0ee6c1"; logging-data="24230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+8w2X1p348D2fjU855Qcw+hub1HA9T88=" User-Agent: Pan/0.146 (Hic habitat felicitas; 8107378 git@gitlab.gnome.org:GNOME/pan.git) Cancel-Lock: sha1:Wz/ZEnwc3AyR0Wuf0dtbdVXTGyk= Xref: csiph.com comp.lang.java.programmer:39573 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