github.com/driusan/dgit@v0.0.0-20221118233547-f39f0c15edbb/git/indexpack_test.go (about) 1 package git 2 3 import ( 4 "bytes" 5 "io" 6 "io/ioutil" 7 "testing" 8 ) 9 10 func BenchmarkIndexPackFromFile(b *testing.B) { 11 // A random small pack file, the same as one from TestUnpackObjects. 12 // OFS_DELTA chain with a length of 2. It's not a very realistic 13 // benchmark, but it's better than storing a large amount of test 14 // data in git to be able to test sometihng more realistic. 15 data := []byte{0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0xbc, 0x08, 0x78, 0x9c, 16 0x73, 0xe4, 0x72, 0xc4, 0x09, 0x9d, 0xb8, 0x9c, 0xb9, 0x5c, 0xb8, 0x5c, 0xe9, 0x46, 0x03, 0x00, 17 0xcc, 0xc9, 0x15, 0x0f, 0x65, 0x18, 0x78, 0x9c, 0xeb, 0x61, 0x2c, 0x9a, 0x50, 0x04, 0x00, 0x05, 18 0xad, 0x02, 0x02, 0x65, 0x0f, 0x78, 0x9c, 0x2b, 0x4a, 0x9a, 0x28, 0x90, 0x04, 0x00, 0x05, 0xfc, 19 0x01, 0xd8, 0x75, 0xcc, 0x90, 0x92, 0xc3, 0xd9, 0x93, 0xba, 0xcf, 0xe4, 0x1d, 0x7c, 0xed, 0x5d, 20 0x8f, 0x46, 0xdf, 0xc2, 0x19, 0x0f, 21 } 22 c, err := Init(nil, InitOptions{}, "/tmp/indexpackbench") 23 if err != nil { 24 panic(err) 25 } 26 f, err := ioutil.TempFile("", "foo*.pack") 27 if err != nil { 28 panic(err) 29 } 30 buf := bytes.NewBuffer(data) 31 if _, err := io.Copy(f, buf); err != nil { 32 panic(err) 33 } 34 for n := 0; n < b.N; n++ { 35 if _, err := f.Seek(0, io.SeekStart); err != nil { 36 panic(err) 37 } 38 if _, err := IndexAndCopyPack(c, IndexPackOptions{}, f); err != nil { 39 panic(err) 40 } 41 } 42 } 43 44 func BenchmarkIndexPackFromReader(b *testing.B) { 45 // A random small pack file, the same as one from TestUnpackObjects. 46 // OFS_DELTA chain with a length of 2. It's not a very realistic 47 // benchmark, but it's better than storing a large amount of test 48 // data in git to be able to test sometihng more realistic. 49 data := []byte{0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0xbc, 0x08, 0x78, 0x9c, 50 0x73, 0xe4, 0x72, 0xc4, 0x09, 0x9d, 0xb8, 0x9c, 0xb9, 0x5c, 0xb8, 0x5c, 0xe9, 0x46, 0x03, 0x00, 51 0xcc, 0xc9, 0x15, 0x0f, 0x65, 0x18, 0x78, 0x9c, 0xeb, 0x61, 0x2c, 0x9a, 0x50, 0x04, 0x00, 0x05, 52 0xad, 0x02, 0x02, 0x65, 0x0f, 0x78, 0x9c, 0x2b, 0x4a, 0x9a, 0x28, 0x90, 0x04, 0x00, 0x05, 0xfc, 53 0x01, 0xd8, 0x75, 0xcc, 0x90, 0x92, 0xc3, 0xd9, 0x93, 0xba, 0xcf, 0xe4, 0x1d, 0x7c, 0xed, 0x5d, 54 0x8f, 0x46, 0xdf, 0xc2, 0x19, 0x0f, 55 } 56 c, err := Init(nil, InitOptions{}, "/tmp/indexpackbench") 57 if err != nil { 58 panic(err) 59 } 60 for n := 0; n < b.N; n++ { 61 buf := bytes.NewBuffer(data) 62 if _, err := IndexAndCopyPack(c, IndexPackOptions{}, buf); err != nil { 63 panic(err) 64 } 65 } 66 }