MCPcopy
hub / github.com/ipfs/kubo / benchCat

Function benchCat

test/integration/bench_cat_test.go:37–114  ·  view source on GitHub ↗
(b *testing.B, data []byte, conf testutil.LatencyConfig)

Source from the content-addressed store, hash-verified

35}
36
37func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
38 b.StopTimer()
39 ctx, cancel := context.WithCancel(context.Background())
40 defer cancel()
41
42 // create network
43 mn := mocknet.New()
44 mn.SetLinkDefaults(mocknet.LinkOptions{
45 Latency: conf.NetworkLatency,
46 // TODO add to conf. This is tricky because we want 0 values to be functional.
47 Bandwidth: math.MaxInt32,
48 })
49
50 adder, err := core.NewNode(ctx, &core.BuildCfg{
51 Online: true,
52 Host: mock.MockHostOption(mn),
53 })
54 if err != nil {
55 return err
56 }
57 defer adder.Close()
58
59 catter, err := core.NewNode(ctx, &core.BuildCfg{
60 Online: true,
61 Host: mock.MockHostOption(mn),
62 })
63 if err != nil {
64 return err
65 }
66 defer catter.Close()
67
68 adderAPI, err := coreapi.NewCoreAPI(adder)
69 if err != nil {
70 return err
71 }
72
73 catterAPI, err := coreapi.NewCoreAPI(catter)
74 if err != nil {
75 return err
76 }
77
78 err = mn.LinkAll()
79 if err != nil {
80 return err
81 }
82
83 bs1 := []peer.AddrInfo{adder.Peerstore.PeerInfo(adder.Identity)}
84 bs2 := []peer.AddrInfo{catter.Peerstore.PeerInfo(catter.Identity)}
85
86 if err := catter.Bootstrap(bootstrap.BootstrapConfigWithPeers(bs1)); err != nil {
87 return err
88 }
89 if err := adder.Bootstrap(bootstrap.BootstrapConfigWithPeers(bs2)); err != nil {
90 return err
91 }
92
93 added, err := adderAPI.Unixfs().Add(ctx, files.NewBytesFile(data))
94 if err != nil {

Callers 1

benchmarkVarCatFunction · 0.85

Calls 9

UnixfsMethod · 0.95
BytesMethod · 0.95
NewNodeFunction · 0.92
NewCoreAPIFunction · 0.92
CopyMethod · 0.80
CloseMethod · 0.65
AddMethod · 0.65
GetMethod · 0.65
BootstrapMethod · 0.45

Tested by

no test coverage detected