MCPcopy
hub / github.com/opencloud-eu/opencloud / benchmark

Function benchmark

opencloud/pkg/command/benchmark.go:391–510  ·  view source on GitHub ↗
(iterations int, path string)

Source from the content-addressed store, hash-verified

389}
390
391func benchmark(iterations int, path string) error {
392 tests := map[string]func() error{
393 "lockedfile open(wo,c,t) close": func() error {
394 for i := 0; i < iterations; i++ {
395 lockedFile, err := lockedfile.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
396 if err != nil {
397 return err
398 }
399 lockedFile.Close()
400 }
401 return nil
402 },
403 "stat": func() error {
404 for i := 0; i < iterations; i++ {
405 _, err := os.Stat(path)
406 if err != nil {
407 return err
408 }
409 }
410 return nil
411 },
412 "fopen(ro) close": func() error {
413 for i := 0; i < iterations; i++ {
414 h, err := os.OpenFile(path, os.O_RDONLY, 0600)
415 if err != nil {
416 return err
417 }
418 h.Close()
419 }
420 return nil
421 },
422 "fopen(wo,t) write close": func() error {
423 for i := 0; i < iterations; i++ {
424 h, err := os.OpenFile(path, os.O_TRUNC|os.O_WRONLY, 0600)
425 if err != nil {
426 return err
427 }
428 _, err = h.WriteString("1234567890")
429 if err != nil {
430 h.Close()
431 return err
432 }
433 h.Close()
434 }
435 return nil
436 },
437 "fopen(ro) read close": func() error {
438 for i := 0; i < iterations; i++ {
439 bytes := make([]byte, 0, 10)
440 h, err := os.OpenFile(path, os.O_RDONLY, 0600)
441 if err != nil {
442 return err
443 }
444 _, err = h.Read(bytes)
445 if err != nil {
446 h.Close()
447 return err
448 }

Callers 1

BenchmarkSyscallsCommandFunction · 0.70

Calls 10

GetStringFunction · 0.92
CompiledFunction · 0.92
SetMethod · 0.80
CloseMethod · 0.65
StatMethod · 0.65
GetMethod · 0.65
ReadMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45
RenderMethod · 0.45

Tested by

no test coverage detected