github.com/enetx/g@v1.0.80/tests/string_compdecomp_benchmark_test.go (about)

     1  package g_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/enetx/g"
     7  )
     8  
     9  // go test -bench=. -benchmem -count=4
    10  
    11  var alice = g.String(
    12  	"IEFsaWNlIHdhcyBiZWdpbm5pbmcgdG8gZ2V0IHZlcnkgdGlyZWQgb2Ygc2l0dGluZyBieSBoZXIgc2lzdGVyIG9uIHRoZSBiYW5rLCBhbmQgb2YgaGF2aW5nIG5vdGhpbmcgdG8gZG86IG9uY2Ugb3IgdHdpY2Ugc2hlIGhhZCBwZWVwZWQgaW50byB0aGUgYm9vayBoZXIgc2lzdGVyIHdhcyByZWFkaW5nLCBidXQgaXQgaGFkIG5vIHBpY3R1cmVzIG9yIGNvbnZlcnNhdGlvbnMgaW4gaXQsIOKAnGFuZCB3aGF0IGlzIHRoZSB1c2Ugb2YgYSBib29rLOKAnSB0aG91Z2h0IEFsaWNlIOKAnHdpdGhvdXQgcGljdHVyZXMgb3IgY29udmVyc2F0aW9ucz/igJ0KClNvIHNoZSB3YXMgY29uc2lkZXJpbmcgaW4gaGVyIG93biBtaW5kIChhcyB3ZWxsIGFzIHNoZSBjb3VsZCwgZm9yIHRoZSBob3QgZGF5IG1hZGUgaGVyIGZlZWwgdmVyeSBzbGVlcHkgYW5kIHN0dXBpZCksIHdoZXRoZXIgdGhlIHBsZWFzdXJlIG9mIG1ha2luZyBhIGRhaXN5LWNoYWluIHdvdWxkIGJlIHdvcnRoIHRoZSB0cm91YmxlIG9mIGdldHRpbmcgdXAgYW5kIHBpY2tpbmcgdGhlIGRhaXNpZXMsIHdoZW4gc3VkZGVubHkgYSBXaGl0ZSBSYWJiaXQgd2l0aCBwaW5rIGV5ZXMgcmFuIGNsb3NlIGJ5IGhlci4KClRoZXJlIHdhcyBub3RoaW5nIHNvIHZlcnkgcmVtYXJrYWJsZSBpbiB0aGF0OyBub3IgZGlkIEFsaWNlIHRoaW5rIGl0IHNvIHZlcn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qgb3BlbiBhbnkgb2YgdGhlbS4gSG93ZXZlciwgb24gdGhlIHNlY29uZCB0aW1lIHJvdW5kLCBzaGUgY2FtZSB1cG9uIGEgbG93IGN1cnRhaW4gc2hlIGhhZCBub3Qgbm90aWNlZCBiZWZvcmUsIGFuZCBiZWhpbmQgaXQgd2FzIGEgbGl0dGxlIGRvb3IgYWJvdXQgZmlmdGVlbiBpbmNoZXMgaGlnaDogc2hlIHRyaWVkIHRoZSBsaXR0bGUgZ29sZGVuIGtleSBpbiB0aGUgbG9jaywgYW5kIHRvIGhlciBncmVhdCBkZWxpZ2h0IGl0IGZpdHRlZCEg",
    13  )
    14  
    15  func BenchmarkGzip(b *testing.B) {
    16  	b.ResetTimer()
    17  
    18  	for n := 0; n < b.N; n++ {
    19  		alice.Comp().Gzip()
    20  	}
    21  }
    22  
    23  func BenchmarkFlate(b *testing.B) {
    24  	b.ResetTimer()
    25  
    26  	for n := 0; n < b.N; n++ {
    27  		alice.Comp().Flate()
    28  	}
    29  }
    30  
    31  func BenchmarkZlib(b *testing.B) {
    32  	b.ResetTimer()
    33  
    34  	for n := 0; n < b.N; n++ {
    35  		alice.Comp().Zlib()
    36  	}
    37  }