The Groovy profiler, GProf is a profiling module for Groovy. It allows you to determine which parts of a program are taking most of the execution time as the GNU profiler, gprof does for C and C++.
@Grab('org.gperfutils:gprof:0.2.0')
or other ways to install from the Maven Central repository or build a jar file from source code.
In the following code, GProf shows you that YourApp has two slow operation; one is a task that is short but repeated many times and another is a long task.
class YourApp { void start() { def foo = new Foo() for (int i = 0; i < 100; i++) { foo.doShortTask() } def bar = new Bar() bar.doLongTask() } }
class Bar { void doLongTask() { for (int i = 0; i < 1000000; i++); } }
class Foo { void doShortTask() { for (int i = 0; i < 10000; i++); } }
profile { // or new gprof.Profiler().run { new YourApp().start() }.prettyPrint()
/ stdout % calls total ms ms/call min ms max ms method class 47.59 1 54.33 54.33 54.33 54.33 doLongTask Bar 40.05 100 45.72 0.46 0.29 2.09 doShortTask Foo 11.92 1 13.61 13.61 13.61 13.61 start YourApp 0.18 1 0.21 0.21 0.21 0.21 ctor YourApp 0.13 1 0.14 0.14 0.14 0.14 ctor Bar 0.13 1 0.14 0.14 0.14 0.14 ctor Foo /
GProf is copyright 2013 Masato Nagai and licensed under the term of the Apache License, Version 2.0. See the file LICENSE for the full license.