use extracted unit package
Brian Tiger Chow committed
Jan 20, 2015 at 04:25 UTC
6b8d3e3c695d01d8f3faba4876a4e25493ba1f44
5 files changed
+52
-83
test/epictest/addcat_test.go
+2
-1
@@ -15,6 +15,7 @@ import (
15
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
16
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
17
"github.com/jbenet/go-ipfs/p2p/peer"
18
+ "github.com/jbenet/go-ipfs/thirdparty/unit"
19
errors "github.com/jbenet/go-ipfs/util/debugerror"
20
testutil "github.com/jbenet/go-ipfs/util/testutil"
21
)
@@ -28,7 +29,7 @@ func Test1KBInstantaneous(t *testing.T) {
29
BlockstoreLatency: 0,
30
}
31
31
- if err := DirectAddCat(RandomBytes(1*KB), conf); err != nil {
32
+ if err := DirectAddCat(RandomBytes(1*unit.KB), conf); err != nil {
33
t.Fatal(err)
34
}
35
}
test/epictest/bench_test.go
+48
-47
@@ -3,6 +3,7 @@ package epictest
3
import (
4
"testing"
5
6
+ "github.com/jbenet/go-ipfs/thirdparty/unit"
7
testutil "github.com/jbenet/go-ipfs/util/testutil"
8
)
9
@@ -22,62 +23,62 @@ func benchmarkAddCat(numBytes int64, conf testutil.LatencyConfig, b *testing.B)
23
24
var instant = testutil.LatencyConfig{}.All_Instantaneous()
25
25
-func BenchmarkInstantaneousAddCat1KB(b *testing.B) { benchmarkAddCat(1*KB, instant, b) }
26
-func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, instant, b) }
27
-func BenchmarkInstantaneousAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, instant, b) }
28
-func BenchmarkInstantaneousAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, instant, b) }
29
-func BenchmarkInstantaneousAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, instant, b) }
30
-func BenchmarkInstantaneousAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, instant, b) }
31
-func BenchmarkInstantaneousAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, instant, b) }
32
-func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, instant, b) }
33
-func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, instant, b) }
34
-func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, instant, b) }
26
+func BenchmarkInstantaneousAddCat1KB(b *testing.B) { benchmarkAddCat(1*unit.KB, instant, b) }
27
+func BenchmarkInstantaneousAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, instant, b) }
28
+func BenchmarkInstantaneousAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, instant, b) }
29
+func BenchmarkInstantaneousAddCat4MB(b *testing.B) { benchmarkAddCat(4*unit.MB, instant, b) }
30
+func BenchmarkInstantaneousAddCat8MB(b *testing.B) { benchmarkAddCat(8*unit.MB, instant, b) }
31
+func BenchmarkInstantaneousAddCat16MB(b *testing.B) { benchmarkAddCat(16*unit.MB, instant, b) }
32
+func BenchmarkInstantaneousAddCat32MB(b *testing.B) { benchmarkAddCat(32*unit.MB, instant, b) }
33
+func BenchmarkInstantaneousAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.MB, instant, b) }
34
+func BenchmarkInstantaneousAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, instant, b) }
35
+func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, instant, b) }
36
37
var routing = testutil.LatencyConfig{}.Routing_Slow()
38
38
-func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, routing, b) }
39
-func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, routing, b) }
40
-func BenchmarkRoutingSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, routing, b) }
41
-func BenchmarkRoutingSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, routing, b) }
42
-func BenchmarkRoutingSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, routing, b) }
43
-func BenchmarkRoutingSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, routing, b) }
44
-func BenchmarkRoutingSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, routing, b) }
45
-func BenchmarkRoutingSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, routing, b) }
46
-func BenchmarkRoutingSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, routing, b) }
47
-func BenchmarkRoutingSlowAddCat512MB(b *testing.B) { benchmarkAddCat(512*MB, routing, b) }
39
+func BenchmarkRoutingSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, routing, b) }
40
+func BenchmarkRoutingSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, routing, b) }
41
+func BenchmarkRoutingSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*unit.MB, routing, b) }
42
+func BenchmarkRoutingSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*unit.MB, routing, b) }
43
+func BenchmarkRoutingSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*unit.MB, routing, b) }
44
+func BenchmarkRoutingSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*unit.MB, routing, b) }
45
+func BenchmarkRoutingSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.MB, routing, b) }
46
+func BenchmarkRoutingSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, routing, b) }
47
+func BenchmarkRoutingSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, routing, b) }
48
+func BenchmarkRoutingSlowAddCat512MB(b *testing.B) { benchmarkAddCat(512*unit.MB, routing, b) }
49
50
var network = testutil.LatencyConfig{}.Network_NYtoSF()
51
51
-func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, network, b) }
52
-func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, network, b) }
53
-func BenchmarkNetworkSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, network, b) }
54
-func BenchmarkNetworkSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, network, b) }
55
-func BenchmarkNetworkSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, network, b) }
56
-func BenchmarkNetworkSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, network, b) }
57
-func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, network, b) }
58
-func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, network, b) }
59
-func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, network, b) }
52
+func BenchmarkNetworkSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, network, b) }
53
+func BenchmarkNetworkSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, network, b) }
54
+func BenchmarkNetworkSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*unit.MB, network, b) }
55
+func BenchmarkNetworkSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*unit.MB, network, b) }
56
+func BenchmarkNetworkSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*unit.MB, network, b) }
57
+func BenchmarkNetworkSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*unit.MB, network, b) }
58
+func BenchmarkNetworkSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.MB, network, b) }
59
+func BenchmarkNetworkSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, network, b) }
60
+func BenchmarkNetworkSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, network, b) }
61
62
var hdd = testutil.LatencyConfig{}.Blockstore_7200RPM()
63
63
-func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*MB, hdd, b) }
64
-func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*MB, hdd, b) }
65
-func BenchmarkBlockstoreSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*MB, hdd, b) }
66
-func BenchmarkBlockstoreSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*MB, hdd, b) }
67
-func BenchmarkBlockstoreSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*MB, hdd, b) }
68
-func BenchmarkBlockstoreSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, hdd, b) }
69
-func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*MB, hdd, b) }
70
-func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, hdd, b) }
71
-func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, hdd, b) }
64
+func BenchmarkBlockstoreSlowAddCat1MB(b *testing.B) { benchmarkAddCat(1*unit.MB, hdd, b) }
65
+func BenchmarkBlockstoreSlowAddCat2MB(b *testing.B) { benchmarkAddCat(2*unit.MB, hdd, b) }
66
+func BenchmarkBlockstoreSlowAddCat4MB(b *testing.B) { benchmarkAddCat(4*unit.MB, hdd, b) }
67
+func BenchmarkBlockstoreSlowAddCat8MB(b *testing.B) { benchmarkAddCat(8*unit.MB, hdd, b) }
68
+func BenchmarkBlockstoreSlowAddCat16MB(b *testing.B) { benchmarkAddCat(16*unit.MB, hdd, b) }
69
+func BenchmarkBlockstoreSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*unit.MB, hdd, b) }
70
+func BenchmarkBlockstoreSlowAddCat64MB(b *testing.B) { benchmarkAddCat(64*unit.MB, hdd, b) }
71
+func BenchmarkBlockstoreSlowAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, hdd, b) }
72
+func BenchmarkBlockstoreSlowAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, hdd, b) }
73
74
var mixed = testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
75
75
-func BenchmarkMixedAddCat1MBXX(b *testing.B) { benchmarkAddCat(1*MB, mixed, b) }
76
-func BenchmarkMixedAddCat2MBXX(b *testing.B) { benchmarkAddCat(2*MB, mixed, b) }
77
-func BenchmarkMixedAddCat4MBXX(b *testing.B) { benchmarkAddCat(4*MB, mixed, b) }
78
-func BenchmarkMixedAddCat8MBXX(b *testing.B) { benchmarkAddCat(8*MB, mixed, b) }
79
-func BenchmarkMixedAddCat16MBX(b *testing.B) { benchmarkAddCat(16*MB, mixed, b) }
80
-func BenchmarkMixedAddCat32MBX(b *testing.B) { benchmarkAddCat(32*MB, mixed, b) }
81
-func BenchmarkMixedAddCat64MBX(b *testing.B) { benchmarkAddCat(64*MB, mixed, b) }
82
-func BenchmarkMixedAddCat128MB(b *testing.B) { benchmarkAddCat(128*MB, mixed, b) }
83
-func BenchmarkMixedAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, mixed, b) }
76
+func BenchmarkMixedAddCat1MBXX(b *testing.B) { benchmarkAddCat(1*unit.MB, mixed, b) }
77
+func BenchmarkMixedAddCat2MBXX(b *testing.B) { benchmarkAddCat(2*unit.MB, mixed, b) }
78
+func BenchmarkMixedAddCat4MBXX(b *testing.B) { benchmarkAddCat(4*unit.MB, mixed, b) }
79
+func BenchmarkMixedAddCat8MBXX(b *testing.B) { benchmarkAddCat(8*unit.MB, mixed, b) }
80
+func BenchmarkMixedAddCat16MBX(b *testing.B) { benchmarkAddCat(16*unit.MB, mixed, b) }
81
+func BenchmarkMixedAddCat32MBX(b *testing.B) { benchmarkAddCat(32*unit.MB, mixed, b) }
82
+func BenchmarkMixedAddCat64MBX(b *testing.B) { benchmarkAddCat(64*unit.MB, mixed, b) }
83
+func BenchmarkMixedAddCat128MB(b *testing.B) { benchmarkAddCat(128*unit.MB, mixed, b) }
84
+func BenchmarkMixedAddCat256MB(b *testing.B) { benchmarkAddCat(256*unit.MB, mixed, b) }
test/epictest/three_legged_cat_test.go
+2
-1
@@ -11,6 +11,7 @@ import (
11
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
12
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
13
"github.com/jbenet/go-ipfs/p2p/peer"
14
+ "github.com/jbenet/go-ipfs/thirdparty/unit"
15
errors "github.com/jbenet/go-ipfs/util/debugerror"
16
testutil "github.com/jbenet/go-ipfs/util/testutil"
17
)
@@ -21,7 +22,7 @@ func TestThreeLeggedCat(t *testing.T) {
22
RoutingLatency: 0,
23
BlockstoreLatency: 0,
24
}
24
- if err := RunThreeLeggedCat(RandomBytes(1*KB), conf); err != nil {
25
+ if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
26
t.Fatal(err)
27
}
28
}
test/epictest/unit.go
-10
@@ -1,11 +1 @@
1
package epictest
2
-
3
-const (
4
- _ = iota // ignore first value by assigning to blank identifier
5
- KB = 1 << (10 * iota)
6
- MB
7
- GB
8
- TB
9
- PB
10
- EB
11
-)
test/epictest/unit_test.go
-24
@@ -1,26 +1,2 @@
1
package epictest
2
3
-import "testing"
4
-
5
-// and the award for most meta goes to...
6
-
7
-func TestByteSizeUnit(t *testing.T) {
8
- if 1*KB != 1*1024 {
9
- t.Fatal(1 * KB)
10
- }
11
- if 1*MB != 1*1024*1024 {
12
- t.Fail()
13
- }
14
- if 1*GB != 1*1024*1024*1024 {
15
- t.Fail()
16
- }
17
- if 1*TB != 1*1024*1024*1024*1024 {
18
- t.Fail()
19
- }
20
- if 1*PB != 1*1024*1024*1024*1024*1024 {
21
- t.Fail()
22
- }
23
- if 1*EB != 1*1024*1024*1024*1024*1024*1024 {
24
- t.Fail()
25
- }
26
-}