@@ -16,7 +16,6 @@ import (
16
16
"flag"
17
17
"fmt"
18
18
"internal/cfg"
19
- "internal/testmath"
20
19
"os"
21
20
"os/exec"
22
21
"path/filepath"
@@ -464,67 +463,3 @@ func RunWithTimeout(t testing.TB, cmd *exec.Cmd) ([]byte, error) {
464
463
465
464
return b .Bytes (), err
466
465
}
467
-
468
- // CheckLinear checks if the function produced by f scales linearly.
469
- //
470
- // f must accept a scale factor which causes the input to the function it
471
- // produces to scale by that factor.
472
- func CheckLinear (t * testing.T , f func (scale float64 ) func (* testing.B )) {
473
- MustHaveExec (t )
474
-
475
- if os .Getenv ("GO_PERF_UNIT_TEST" ) == "" {
476
- // Invoke the same test as a subprocess with the GO_PERF_UNIT_TEST environment variable set.
477
- // We create a subprocess for two reasons:
478
- //
479
- // 1. There's no other way to set the benchmarking parameters of testing.Benchmark.
480
- // 2. Since we're effectively running a performance test, running in a subprocess grants
481
- // us a little bit more isolation than using the same process.
482
- //
483
- // As an alternative, we could fairly easily reimplement the timing code in testing.Benchmark,
484
- // but a subprocess is just as easy to create.
485
-
486
- selfCmd := CleanCmdEnv (exec .Command (os .Args [0 ], "-test.v" , fmt .Sprintf ("-test.run=^%s$" , t .Name ()), "-test.benchtime=1x" ))
487
- selfCmd .Env = append (selfCmd .Env , "GO_PERF_UNIT_TEST=1" )
488
- output , err := RunWithTimeout (t , selfCmd )
489
- if err != nil {
490
- t .Error (err )
491
- t .Logf ("--- subprocess output ---\n %s" , string (output ))
492
- }
493
- if bytes .Contains (output , []byte ("insignificant result" )) {
494
- t .Skip ("insignificant result" )
495
- }
496
- return
497
- }
498
-
499
- // Pick a reasonable sample count.
500
- const count = 10
501
-
502
- // Collect samples for scale factor 1.
503
- x1 := make ([]testing.BenchmarkResult , 0 , count )
504
- for i := 0 ; i < count ; i ++ {
505
- x1 = append (x1 , testing .Benchmark (f (1.0 )))
506
- }
507
-
508
- // Collect samples for scale factor 2.
509
- x2 := make ([]testing.BenchmarkResult , 0 , count )
510
- for i := 0 ; i < count ; i ++ {
511
- x2 = append (x2 , testing .Benchmark (f (2.0 )))
512
- }
513
-
514
- // Run a t-test on the results.
515
- r1 := testmath .BenchmarkResults (x1 )
516
- r2 := testmath .BenchmarkResults (x2 )
517
- result , err := testmath .TwoSampleWelchTTest (r1 , r2 , testmath .LocationDiffers )
518
- if err != nil {
519
- t .Fatalf ("failed to run t-test: %v" , err )
520
- }
521
- if result .P > 0.005 {
522
- // Insignificant result.
523
- t .Skip ("insignificant result" )
524
- }
525
-
526
- // Let ourselves be within 3x; 2x is too strict.
527
- if m1 , m2 := r1 .Mean (), r2 .Mean (); 3.0 * m1 < m2 {
528
- t .Fatalf ("failure to scale linearly: µ_1=%s µ_2=%s p=%f" , time .Duration (m1 ), time .Duration (m2 ), result .P )
529
- }
530
- }
0 commit comments