From 6c728f2b02c4d1def86dc258b0baaf200f3e2811 Mon Sep 17 00:00:00 2001 From: Szczepan Faber Date: Thu, 9 Feb 2012 21:49:06 +0100 Subject: [PATCH] Spiked making performance testing outside of the gradle main project. It's not really possible as I need various things: 1. good way of running gradle (tooling api is almost there) 2. good way of using previous versions of gradle So... the performance testing probably goes under the main gradle project. --- performanceTest/build.gradle | 11 ++++- .../gradle/peformance/PerformanceTest.groovy | 48 +++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/performanceTest/build.gradle b/performanceTest/build.gradle index fa846c1d9bf2..b07da1b149d1 100644 --- a/performanceTest/build.gradle +++ b/performanceTest/build.gradle @@ -7,6 +7,7 @@ idea.project.jdkName = '1.6' repositories { mavenCentral() + mavenRepo(url: 'http://repo.gradle.org/gradle/libs-releases-local') } configurations { @@ -16,9 +17,15 @@ configurations { dependencies { junit 'junit:junit:4.10' groovy localGroovy() + testCompile 'junit:junit:4.10' + + //spock testCompile 'org.spockframework:spock-core:0.5-groovy-1.8@jar', - 'org.objenesis:objenesis:1.2', 'cglib:cglib-nodep:2.2', - 'junit:junit:4.10' + 'org.objenesis:objenesis:1.2', 'cglib:cglib-nodep:2.2' + + //tooling api + testCompile 'org.gradle:gradle-tooling-api:1.0-milestone-7' + testRuntime 'org.slf4j:slf4j-simple:1.6.4' } task small(type: GeneratorTask, description: 'Generates a small project') { diff --git a/performanceTest/src/test/groovy/org/gradle/peformance/PerformanceTest.groovy b/performanceTest/src/test/groovy/org/gradle/peformance/PerformanceTest.groovy index 56f36fcfcc06..e1e78d9c5292 100644 --- a/performanceTest/src/test/groovy/org/gradle/peformance/PerformanceTest.groovy +++ b/performanceTest/src/test/groovy/org/gradle/peformance/PerformanceTest.groovy @@ -1,14 +1,56 @@ package org.gradle.peformance import spock.lang.Specification +import org.gradle.tooling.GradleConnector /** * by Szczepan Faber, created at: 2/9/12 */ class PerformanceTest extends Specification { - def "foo"() { - expect: - 1==1 + def "small project"() { + given: + def projectDir = findProjectDir("small") + + when: + int m6result = executionTime { + def connection = GradleConnector.newConnector() + .forProjectDirectory(projectDir) + .searchUpwards(false) + .useGradleVersion("1.0-milestone-6") + .connect() + + connection.newBuild().forTasks('clean', 'build').run() + } + + int m7result = executionTime { + def connection = GradleConnector.newConnector() + .forProjectDirectory(projectDir) + .searchUpwards(false) + .useGradleVersion("1.0-milestone-7") + .connect() + + connection.newBuild().forTasks('clean', 'build').run() + } + + then: + m7result <= m6result + } + + long executionTime(Closure operation) { + long before = System.currentTimeMillis() + operation() + return System.currentTimeMillis() - before + } + + File findProjectDir(String name) { + def projectDir = new File("build/small").absoluteFile + if (!projectDir.isDirectory()) { + def message = "Looks like the sample '$name' was not generated.\n" + + "I've tried to find it at: $projectDir\n" + + "Please run 'gradle $name' to generate the sample." + assert false: message + } + projectDir } }