-
Notifications
You must be signed in to change notification settings - Fork 5
/
experiment_test.go
219 lines (209 loc) · 5.39 KB
/
experiment_test.go
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// -----------------------------------------------------------------------------
// github.com/balacode/go-delta go-delta/[experiment_test.go]
// (c) balarabe@protonmail.com License: MIT
// -----------------------------------------------------------------------------
package delta
// to generate a test coverage report for the whole module use:
// go test -coverprofile cover.out
// go tool cover -html=cover.out
import (
"testing"
)
const RunExperiments = false
// -----------------------------------------------------------------------------
// # Experimental / Auxiliary Tests
// go test --run Test01
func Test01(t *testing.T) {
if !RunExperiments {
return
}
if PrintTestNames {
printTestName()
}
PL("Test01 " + Line)
//
cmap1 := makeMap(readData("test1.zip"))
PL("Created cmap1. len(cmap1):", len(cmap1.m))
//
cmap2 := makeMap(readData("test2.zip"))
PL("Created cmap2. len(cmap2):", len(cmap2.m))
//
if false {
const MaxLines = 0
i := 1
for k, v := range cmap1.m {
PL("key:", k, "val:", v)
i++
if i > MaxLines {
break
}
}
}
if true {
for k, v := range cmap2.m {
_, exist := cmap1.get(k)
PL("key:", k, "val:", v, "exist:", exist)
}
}
} // Test01
// go test --run Test02
func Test02(t *testing.T) {
if !RunExperiments {
return
}
if PrintTestNames {
printTestName()
}
var a, b []byte
switch 5 {
case 1:
a = ab(AtoM + " " + AtoS + " " + AtoZ)
b = ab("0x0x0x" + AtoZ + " " + AtoZ + " " + AtoZ + " " + Nums)
case 2:
a = ab(AtoM + " " + AtoS + " " + AtoZ)
b = ab(atoz + " " + atoz + " " + atoz + " " + Nums)
case 3:
/*
Target array's size: 16,994,304 bytes
-
Before optimizing makeMap():
--------------------------------------------------------------
uncompressed delta length: 1,855,440 bytes
compressed delta length: 704,583 (4.15% of target's size)
elapsed time: 171.4 seconds
--------------------------------------------------------------
171.25880: delta.Make
0.16411: makeHash
3.78551: makeMap
165.82172: longestMatch
0.09878: write
0.13109: compressBytes
-
After optimizing makeMap():
--------------------------------------------------------------
uncompressed delta length: 1,952,772 bytes
compressed delta length: 729,574 (4.29% of target's size)
elapsed time: 2.4 seconds
--------------------------------------------------------------
2.40135: delta.Make
0.11608: makeHash
1.28985: makeMap
0.14999: longestMatch
0.07882: write
0.09806: compressBytes
-
After adding backward-scanning in longestMatch()
--------------------------------------------------------------
uncompressed delta length: 1,675,811 bytes
compressed delta length: 666,880 (3.92% of target's size)
elapsed time: 2.4 seconds
--------------------------------------------------------------
2.45898: delta.Make
0.15910: makeHash
1.49399: makeMap
0.16595: longestMatch
0.07311: write
0.12408: compressBytes
*/
a = readData("test1.file")
b = readData("test2.file")
PL("loaded data")
case 4:
/*
target size: 10,356,821
uncompressed delta: 5,414,754
compressed delta: 5,258,684 (50.7% of file size)
elapsed time: 6.2 seconds
*/
a = readData("test1.zip")
b = readData("test2.zip")
PL("loaded data")
case 5:
/*
target size: 17,096,704 bytes
uncompressed delta: 64,081 bytes
compressed delta: 25,967 (50.7% of file size)
elapsed time: 2.06 seconds
--------------------------------------------------------------
2.06019: delta.Make
0.11507: makeHash
1.44146: makeMap
0.05109: longestMatch
0.00349: write
0.00600: compressBytes
3.67731
*/
a = readData("day1.data")
b = readData("day2.data")
PL("loaded data")
}
if DebugTiming {
tmr.Start("delta.Make")
}
{
d := Make(a, b)
d.Bytes()
}
if DebugTiming {
tmr.Stop("delta.Make")
tmr.Print()
}
} // Test02
// go test --run Test03
func Test03(t *testing.T) {
if !RunExperiments {
return
}
if PrintTestNames {
printTestName()
}
var a, b []byte
switch 1 {
case 1:
a = ab(AtoM + " " + AtoS + " " + AtoZ)
b = ab("000" + AtoZ + " " + AtoZ + " " + AtoZ + " " + Nums)
}
// -------------------------------------------------------------------------
PL("\n" + Line)
d1 := Make(a, b)
PL("CREATED d1:")
d1.Dump()
//
dbytes := d1.Bytes()
PL("got 'dbytes'")
// -------------------------------------------------------------------------
PL("\n" + Line)
if DebugTiming {
tmr.Start("Load")
}
d2, err := Load(dbytes)
PL("CREATED d2: err:", err)
d2.Dump()
if DebugTiming {
tmr.Stop("Load")
tmr.Print()
}
} // Test03
// go test --run Test04
func Test04(t *testing.T) {
if !RunExperiments {
return
}
if PrintTestNames {
printTestName()
}
d := Delta{
sourceSize: 111,
sourceHash: []byte("SOURCE"),
targetSize: 222,
targetHash: []byte("TARGET"),
newCount: 333,
oldCount: 444,
parts: []deltaPart{
{},
{},
},
}
PL(d.GoString())
} // Test04
// end