<commit_before>package org.gradle.peformance

import spock.lang.Specification
import org.gradle.integtests.fixtures.*

/**
 * by <NAME>, created at: 2/9/12
 */
class PerformanceTest extends Specification {

    def "small project"() {
        given:
        def GradleDistribution current = new GradleDistribution()
        def previous = new ReleasedVersions(current).last

        def projectDir = findProjectDir("small")

        when:
        def previousExecuter = executer(previous, projectDir)
        int previousResult = executionTime {
            previousExecuter.run()
        }

        def projectDir2 = findProjectDir("small")

        def currentExecuter = executer(current, projectDir2)
        int currentResult = executionTime {
            currentExecuter.run()
        }

        then:
        previousResult <= currentResult
    }

    private GradleExecuter executer(BasicGradleDistribution dist, File projectDir) {
        def executer
        if (dist instanceof GradleDistribution) {
            executer = new GradleDistributionExecuter(GradleDistributionExecuter.Executer.forking, dist)
        } else {
            executer = dist.executer()
        }
        return executer.withArguments('-u').inDirectory(projectDir).withTasks('clean', 'build')
    }

    long executionTime(Closure operation) {
        long before = System.currentTimeMillis()
        operation()
        return System.currentTimeMillis() - before
    }

    File findProjectDir(String name) {
        def base = "subprojects/performance/build"
        def locations = ["$base/$name", "../../$base/$name"]
        def dirs = locations.collect { new File(it).absoluteFile }
        for (File dir: dirs) {
            if (dir.isDirectory()) {
                return dir
            }
        }
        def message = "Looks like the sample '$name' was not generated.\nI've tried to find it at:\n"
        dirs.each { message += "  $it\n" }
        message +="Please run 'gradlew performance:$name' to generate the sample."
        assert false: message
    }
}<commit_msg>Some refactoring.<commit_after>package org.gradle.peformance

import spock.lang.Specification
import org.gradle.integtests.fixtures.*

/**
 * by <NAME>, created at: 2/9/12
 */
class PerformanceTest extends Specification {

    def current = new GradleDistribution()
    def previous = new ReleasedVersions(current).last

    def "small project"() {
        when:
        def previousExecuter = executer(previous, "small")
        int previousResult = executionTime {
            previousExecuter.run()
        }

        def currentExecuter = executer(current, "small")
        int currentResult = executionTime {
            currentExecuter.run()
        }

        then:
        previousResult <= currentResult
    }

    private GradleExecuter executer(BasicGradleDistribution dist, String testProjectName) {
        def projectDir = findProjectDir(testProjectName)
        def executer
        if (dist instanceof GradleDistribution) {
            executer = new GradleDistributionExecuter(GradleDistributionExecuter.Executer.forking, dist)
        } else {
            executer = dist.executer()
        }
        return executer.withArguments('-u').inDirectory(projectDir).withTasks('clean', 'build')
    }

    long executionTime(Closure operation) {
        long before = System.currentTimeMillis()
        operation()
        return System.currentTimeMillis() - before
    }

    File findProjectDir(String name) {
        def base = "subprojects/performance/build"
        def locations = ["$base/$name", "../../$base/$name"]
        def dirs = locations.collect { new File(it).absoluteFile }
        for (File dir: dirs) {
            if (dir.isDirectory()) {
                return dir
            }
        }
        def message = "Looks like the test project '$name' was not generated.\nI've tried to find it at:\n"
        dirs.each { message += "  $it\n" }
        message +="Please run 'gradlew performance:$name' to generate the test project."
        assert false: message
    }
}
{'fraction_non_alphanumeric': 0.09955752212389381, 'fraction_numerical': 0.0024582104228121925, 'mean_word_length': 2.399331662489557, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3320866', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1060, 'n_words': 276}