Exemplo n.º 1
0
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()
}
Exemplo n.º 2
0
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()
}
Exemplo n.º 3
0
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()
}