4

I am trying to wrap the caliper code in junit so the performance tests run as part of my unit tests. It seems to work - the caliper test actually runs, but it doesn't exit successfully. What's the proper way to set this stuff up?

import static org.junit.Assert.*;

import org.junit.Test;

import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;

public class CaliperBenchmarkExample extends SimpleBenchmark {

        public void timeNanoTime(int reps) {
          for (int i = 0; i < reps; i++) {
            System.nanoTime();
          }
        }

    @Test
    public void testPerformance() {
        Runner.main(CaliperBenchmarkExample.class, new String[] { });
        assertTrue(true);
    }
}
4

1 に答える 1

4

Caliper テストを JUnit テストとして実行するメカニズムはありません。Caliper が子プロセスを fork してベンチマークを分離する方法のため、これを行うのは複雑です。また、Caliper ベンチマークは数秒間実行される傾向があり、テストのパフォーマンスが低下する可能性があります。

Caliper ベンチマークを継続的に実行するオープン ソース プロジェクトであるcaliper-ciを調査することをお勧めします。

于 2012-03-11T13:44:32.260 に答える