1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2023 The rust-ggstd authors. All rights reserved.
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
use cratebytes;
use crateflate;
use crateio as ggio;
// var suites = []struct{ name, file string }{
// // Digits is the digits of the irrational number e. Its decimal representation
// // does not repeat, but there are only 10 possible digits, so it should be
// // reasonably compressible.
// {"Digits", "../testdata/e.txt"},
// // Newton is Isaac Newtons's educational text on Opticks.
// {"Newton", "../../testdata/Isaac.Newton-Opticks.txt"},
// }
// fn BenchmarkDecode(b *testing.B) {
// doBench(b, fn(b *testing.B, buf0 [u8], level, n int) {
// b.ReportAllocs()
// b.StopTimer()
// b.SetBytes(int64(n))
// compressed := new(bytes::Buffer::new())
// w, err := new_writer(compressed, level)
// if err != nil {
// b.Fatal(err)
// }
// for i := 0; i < n; i += len(buf0) {
// if len(buf0) > n-i {
// buf0 = buf0[..n-i]
// }
// ggio::copy(w, bytes::Reader::new(buf0))
// }
// w.close()
// buf1 := compressed.bytes()
// buf0, compressed, w = nil, nil, nil
// runtime.GC()
// b.StartTimer()
// for i := 0; i < b.N; i += 1 {
// ggio::copy(ggio::Discard::new(), new_reader(bytes::Reader::new(buf1)))
// }
// })
// }
// var levelTests = []struct {
// name string
// level int
// }{
// {"Huffman", HUFFMAN_ONLY},
// {"Speed", BEST_SPEED},
// {"Default", DEFAULT_COMPRESSION},
// {"Compression", BEST_COMPRESSION},
// }
// var sizes = []struct {
// name string
// n int
// }{
// {"1e4", 1e4},
// {"1e5", 1e5},
// {"1e6", 1e6},
// }
// fn doBench(b *testing.B, f fn(b *testing.B, buf [u8], level, n int)) {
// for _, suite := range suites {
// buf, err := os.read_file(suite.file)
// if err != nil {
// b.Fatal(err)
// }
// if len(buf) == 0 {
// b.Fatalf("test file %q has no data", suite.file)
// }
// for _, l := range levelTests {
// for _, s := range sizes {
// b.Run(suite.name+"/"+l.name+"/"+s.name, fn(b *testing.B) {
// f(b, buf, l.level, s.n)
// })
// }
// }
// }
// }