This chapter shows methods of measuring test execution time.
Gradle has a feature called Incremental build. It allows to skip a task when the task not has to be run.
Clean project:
./gradlew :part3.0-measuring:clean
Run build 2 times (run this command in terminal):
./gradlew :part3.0-measuring:test -i
Was there a difference between the execution time in each run?
You can force task to execute (run this command in terminal):
./gradlew :part3.0-measuring:clean :part3.0-measuring:test -i
or (run this command in terminal)
./gradlew :part3.0-measuring:test -i --rerun-tasks
or (run this command in terminal)
./gradlew :part3.0-measuring:test --rerun -i
(run this command in terminal)
./gradlew :part3.0-measuring:test --rerun | grep "BUILD SUCCESSFUL"
BUILD SUCCESSFUL in 5s
(run this command in terminal)
./gradlew :part3.0-measuring:test --rerun -i --profile | grep "profiling report"
See the profiling report at: file:///Users/x/workspaces/parallel-test-execution-workshop/build/reports/profile/profile-2023-03-29-11-21-02.html
A sample output:
Task Execution
Task Duration Result
:part3.0-measuring:test 5.145s
Build Time Tracker is a Gradle plugin to continuously track and report your build times.
-
uncomment plugin configuration in build.gradle (at the beginning and at the end of the file)
plugins { id "net.rdrei.android.buildtimetracker" version "0.11.0" } buildtimetracker { reporters { csv { append true header true output ".build-time.csv" } } }
-
run tests
./gradlew :part3.0-measuring:test --rerun
-
show check results in .build-time.csv
cat .build-time.csv
"timestamp","order","task","success","did_work","skipped","ms","date","cpu","memory","os"
"1680249109103","0",":part3.0-measuring:compileJava","true","false","true","1","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","1",":part3.0-measuring:compileGroovy","true","false","true","0","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","2",":part3.0-measuring:processResources","true","false","true","0","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","3",":part3.0-measuring:classes","true","false","true","0","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","4",":part3.0-measuring:compileTestJava","true","false","true","0","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","5",":part3.0-measuring:compileTestGroovy","true","false","true","12","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","6",":part3.0-measuring:processTestResources","true","false","true","1","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","7",":part3.0-measuring:testClasses","true","false","true","0","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
"1680249109103","8",":part3.0-measuring:test","true","true","false","1000","2023-03-31T07:51:49,103Z","Apple M1 Pro","34359738368","Mac OS X 13.3 aarch64"
(run this command in terminal)
cd part3.0-measuring
for i in {1..5}; do ../gradlew test --rerun 2>&1; done
cd -
./gradlew :part3.0-measuring:stats -Pargs='-stats_file .build-time.csv -task_name :part3.0-measuring:test'
or alternatively (requires Python 3)
./stats.py .build-time.csv :part3.0-measuring:test
min: 960
max: 1036
mean: 999
count: 5
- Check execution time of
test
task with parallel execution disabled. - Enable parallel execution in SpockConfig.groovy and remove
.build-time.csv
file. - Check execution time of
test
task with parallel execution enabled and compare results with previous results.
- Enable parallel execution in SpockConfig.groovy.
- Run
tests
./gradlew --rerun-tasks :part3.0-measuring:test :part3.0-measuring:createTestsExecutionReport
- Check reports
- Run
tests
./gradlew --rerun-tasks :part3.0-measuring:test :part3.0-measuring:createTestsExecutionReport -PdisplaySuites=true
. Report includes execution time of tests (methods/features), suites (classes/specs) and Gradle executors and tasks. - Check reports