Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1 | package security |
| 2 | |
| 3 | // This is a performance benchmark that tests the performance of the |
| 4 | // chain and tree Identity implementations. |
| 5 | // |
| 6 | // Below are the results obtained on running the benchmark tests on April 2, 2014 |
| 7 | // on a desktop machine with a 12 core Intel Xeon E5-1650 @ 3.20GHz processor, |
| 8 | // clock speed of 1200Mhz, and 32GB RAM. |
| 9 | // |
| 10 | // -- chain implementation -- |
| 11 | // |
| 12 | // BenchmarkNewChain 1337091 ns/op |
| 13 | // BenchmarkBlessChain 773872 ns/op |
| 14 | // BenchmarkEncode0BlessingChain 47661 ns/op |
| 15 | // BenchmarkEncode1BlessingChain 52063 ns/op |
| 16 | // BenchmarkDecode0BlessingChain 2594072 ns/op |
| 17 | // BenchmarkDecode1BlessingChain 5092197 ns/op |
| 18 | // |
| 19 | // Wire size with 0 blessings: 676 bytes ("untrusted/X") |
| 20 | // Wire size with 1 blessings: 976 bytes ("untrusted/X/X") |
| 21 | // Wire size with 2 blessings: 1275 bytes ("untrusted/X/X/X") |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 22 | import ( |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 23 | "testing" |
| 24 | "time" |
| 25 | |
| 26 | "veyron2/security" |
| 27 | ) |
| 28 | |
| 29 | func benchmarkBless(b *testing.B, blesser security.PrivateID, blessee security.PublicID) { |
| 30 | b.ResetTimer() |
| 31 | for i := 0; i < b.N; i++ { |
| 32 | if _, err := blesser.Bless(blessee, "friend_bob", 1*time.Second, nil); err != nil { |
| 33 | b.Fatal(err) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | } |
| 38 | |
| 39 | func benchmarkEncode(b *testing.B, id security.PublicID) { |
| 40 | b.ResetTimer() |
| 41 | for i := 0; i < b.N; i++ { |
| 42 | if _, err := encode(id); err != nil { |
| 43 | b.Fatal(err) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func benchmarkDecode(b *testing.B, idBytes []byte) { |
| 49 | b.ResetTimer() |
| 50 | for i := 0; i < b.N; i++ { |
| 51 | if _, err := decode(idBytes); err != nil { |
| 52 | b.Fatal(err) |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // -- chain implementation benchmarks -- |
| 58 | |
| 59 | func BenchmarkNewChain(b *testing.B) { |
| 60 | for i := 0; i < b.N; i++ { |
Srdjan Petrovic | 4b0dfa0 | 2014-07-25 14:13:56 -0700 | [diff] [blame] | 61 | if _, err := newChainPrivateID("X", nil); err != nil { |
Asim Shankar | 70a2887 | 2014-05-13 14:49:20 -0700 | [diff] [blame] | 62 | b.Fatalf("Failed newChainPrivateID #%d: %v", i, err) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func BenchmarkBlessChain(b *testing.B) { |
| 69 | benchmarkBless(b, newChain("alice"), newChain("bob").PublicID()) |
| 70 | } |
| 71 | func BenchmarkEncode0BlessingChain(b *testing.B) { |
| 72 | benchmarkEncode(b, newChain("alice").PublicID()) |
| 73 | } |
| 74 | func BenchmarkEncode1BlessingChain(b *testing.B) { |
| 75 | benchmarkEncode(b, bless(newChain("immaterial").PublicID(), veyronChain, "alice", nil)) |
| 76 | } |
| 77 | |
| 78 | func BenchmarkDecode0BlessingChain(b *testing.B) { |
| 79 | idBytes, err := encode(newChain("alice").PublicID()) |
| 80 | if err != nil { |
| 81 | b.Fatal(err) |
| 82 | } |
| 83 | benchmarkDecode(b, idBytes) |
| 84 | } |
| 85 | |
| 86 | func BenchmarkDecode1BlessingChain(b *testing.B) { |
| 87 | idBytes, err := encode(bless(newChain("immaterial").PublicID(), veyronChain, "alice", nil)) |
| 88 | if err != nil { |
| 89 | b.Fatal(err) |
| 90 | } |
| 91 | benchmarkDecode(b, idBytes) |
| 92 | } |
| 93 | |
| 94 | func TestChainWireSize(t *testing.T) { |
| 95 | const N = 3 |
| 96 | priv := newChain("X") |
| 97 | for i := 0; i < N; i++ { |
| 98 | pub := priv.PublicID() |
| 99 | buf, err := encode(pub) |
| 100 | if err != nil { |
| 101 | t.Fatalf("Failed to encode %q: %v", pub, err) |
| 102 | } |
| 103 | t.Logf("Wire size of %T with %d blessings: %d bytes (%q)", pub, i, len(buf), pub) |
| 104 | priv = derive(bless(pub, priv, "X", nil), priv) |
| 105 | } |
| 106 | } |