Average Time to doSomething()

New to me (StopWatch & awk). Thanks Ben Hall.

* Time how long it takes to doSomething()
* Execute doSomething() many times
* Capture jboss standard out logs in a file named logs.txt
* Determine the average time it takes to doSomething()

// import org.apache.commons.lang.time.StopWatch;
StopWatch stopWatch = new StopWatch();
stopWatch.start();
doSomething();
stopWatch.stop();
System.out.println("StopWatch: " + stopWatch);
$ grep 'StopWatch:' logs.txt > stats.txt
$ tail stats.txt
14:44:25,609 INFO  [STDOUT] StopWatch: 0:00:00.797
14:44:35,843 INFO  [STDOUT] StopWatch: 0:00:00.797
14:44:36,718 INFO  [STDOUT] StopWatch: 0:00:00.859
14:44:41,750 INFO  [STDOUT] StopWatch: 0:00:00.000
14:44:46,093 INFO  [STDOUT] StopWatch: 0:00:00.015
14:44:47,734 INFO  [STDOUT] StopWatch: 0:00:00.844
14:44:52,156 INFO  [STDOUT] StopWatch: 0:00:00.016
14:44:55,359 INFO  [STDOUT] StopWatch: 0:00:00.000
14:44:57,828 INFO  [STDOUT] StopWatch: 0:00:00.000
14:45:05,062 INFO  [STDOUT] StopWatch: 0:00:00.000
$ gawk -F: '{ sum += $6 }; END { print sum }' stats.txt
10.353
$ wc -l stats.txt
193 stats.txt
$ python
>>> average = 10.353 / 193
>>> average
0.053642487046632124
It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply