Skip to content

Commit

Permalink
Spiked making performance testing outside of the gradle main project.…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
mockitoguy committed Feb 11, 2012
1 parent 7159511 commit 6c728f2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
11 changes: 9 additions & 2 deletions performanceTest/build.gradle
Expand Up @@ -7,6 +7,7 @@ idea.project.jdkName = '1.6'

repositories {
mavenCentral()
mavenRepo(url: 'http://repo.gradle.org/gradle/libs-releases-local')
}

configurations {
Expand All @@ -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') {
Expand Down
@@ -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
}
}

0 comments on commit 6c728f2

Please sign in to comment.