func BenchmarkPipingLine(b *testing.B) { b.SetBytes(benchmarkPipingSize) fpath, err := mkRandFile(benchmarkPipingSize) if err != nil { b.Fatalf("temporary file: %v", err) } defer os.Remove(fpath) p := nxpipe.Line( nxpipe.Exec("cat", fpath), nxpipe.Func(func(s *nxpipe.Session) error { _, err := io.Copy(ioutil.Discard, s.Stdin) return err }), ) b.ResetTimer() for i := 0; i < b.N; i++ { err := nxpipe.Run(p) if err != nil { b.Fatalf("exec: %v", err) } } b.StopTimer() }
func BenchmarkPipingLineReverse(b *testing.B) { b.SetBytes(benchmarkPipingSize) fpath, err := mkRandFile(benchmarkPipingSize) if err != nil { b.Fatalf("temporary file: %v", err) } defer os.Remove(fpath) p := nxpipe.Line( nxpipe.Func(func(s *nxpipe.Session) error { f, err := os.Open(fpath) if err != nil { return err } defer f.Close() _, err = io.Copy(s.Stdout, f) return err }), nxpipe.Exec("cat"), ) b.ResetTimer() for i := 0; i < b.N; i++ { err := nxpipe.Run(p) if err != nil { b.Fatalf("exec: %v", err) } } b.StopTimer() }
func BenchmarkPipingShell(b *testing.B) { b.SetBytes(benchmarkPipingSize) fpath, err := mkRandFile(benchmarkPipingSize) if err != nil { b.Fatalf("temporary file: %v", err) } defer os.Remove(fpath) shellcmd := fmt.Sprintf("cat %q | cat > /dev/null", fpath) p := nxpipe.Exec("sh", "-c", shellcmd) b.ResetTimer() for i := 0; i < b.N; i++ { err := nxpipe.Run(p) if err != nil { b.Fatalf("exec: %v", err) } } b.StopTimer() }