square/go-jose — pull request #4 by benburkert (2014-12-22 00:25:53+00:00)
Title: split roundtrip benchmarks into encrypt & decrypt, include throughput numbers

Split up the roundtrip benchmarks into individual `Encrypt` & `Decrypt` benchmarks for different sized test data: `1B`, `64B`, `1KB`, `64KB`, `1MB`, `64MB`. Also show the throughput for comparing the performance of different combinations of primitives for large & small chunks.

```
BenchmarkEncrypt1BWithOAEPAndGCM	10000	114864 ns/op	0.01 MB/s	12638 B/op	75 allocs/op
BenchmarkEncrypt64BWithOAEPAndGCM	10000	115537 ns/op	0.55 MB/s	12686 B/op	75 allocs/op
BenchmarkEncrypt1KBWithOAEPAndGCM	10000	123628 ns/op	8.28 MB/s	13758 B/op	75 allocs/op
BenchmarkEncrypt64KBWithOAEPAndGCM	2000	662730 ns/op	98.89 MB/s	86334 B/op	75 allocs/op
BenchmarkEncrypt1MBWithOAEPAndGCM	200	8785713 ns/op	119.35 MB/s	1069376 B/op	75 allocs/op
BenchmarkEncrypt64MBWithOAEPAndGCM	2	584397283 ns/op	114.83 MB/s	67129720 B/op	76 allocs/op
BenchmarkEncrypt1BWithPKCSAndGCM	10000	127337 ns/op	0.01 MB/s	12424 B/op	69 allocs/op
BenchmarkEncrypt64BWithPKCSAndGCM	10000	128795 ns/op	0.50 MB/s	12472 B/op	69 allocs/op
BenchmarkEncrypt1KBWithPKCSAndGCM	10000	135240 ns/op	7.57 MB/s	13544 B/op	69 allocs/op
BenchmarkEncrypt64KBWithPKCSAndGCM	2000	680176 ns/op	96.35 MB/s	86120 B/op	69 allocs/op
BenchmarkEncrypt1MBWithPKCSAndGCM	200	8772844 ns/op	119.53 MB/s	1069162 B/op	69 allocs/op
BenchmarkEncrypt64MBWithPKCSAndGCM	2	564252096 ns/op	118.93 MB/s	67129504 B/op	70 allocs/op
BenchmarkEncrypt1BWithOAEPAndCBC	10000	118616 ns/op	0.01 MB/s	13241 B/op	84 allocs/op
BenchmarkEncrypt64BWithOAEPAndCBC	10000	120028 ns/op	0.53 MB/s	13608 B/op	85 allocs/op
BenchmarkEncrypt1KBWithOAEPAndCBC	10000	128142 ns/op	7.99 MB/s	16616 B/op	85 allocs/op
BenchmarkEncrypt64KBWithOAEPAndCBC	2000	644277 ns/op	101.72 MB/s	234345 B/op	85 allocs/op
BenchmarkEncrypt1MBWithOAEPAndCBC	200	8524903 ns/op	123.00 MB/s	3183471 B/op	85 allocs/op
BenchmarkEncrypt64MBWithOAEPAndCBC	2	570160413 ns/op	117.70 MB/s	201364448 B/op	87 allocs/op
BenchmarkEncrypt1BWithPKCSAndCBC	10000	127071 ns/op	0.01 MB/s	13024 B/op	78 allocs/op
BenchmarkEncrypt64BWithPKCSAndCBC	10000	126608 ns/op	0.51 MB/s	13392 B/op	79 allocs/op
BenchmarkEncrypt1KBWithPKCSAndCBC	10000	134742 ns/op	7.60 MB/s	16400 B/op	79 allocs/op
BenchmarkEncrypt64KBWithPKCSAndCBC	2000	646394 ns/op	101.39 MB/s	234128 B/op	79 allocs/op
BenchmarkEncrypt1MBWithPKCSAndCBC	200	8484957 ns/op	123.58 MB/s	3183253 B/op	79 allocs/op
BenchmarkEncrypt64MBWithPKCSAndCBC	2	544417620 ns/op	123.27 MB/s	201364224 B/op	81 allocs/op
BenchmarkEncrypt1BWithDirectGCM128	200000	6359 ns/op	0.16 MB/s	2632 B/op	39 allocs/op
BenchmarkEncrypt64BWithDirectGCM128	200000	6804 ns/op	9.40 MB/s	2680 B/op	39 allocs/op
BenchmarkEncrypt1KBWithDirectGCM128	100000	15295 ns/op	66.95 MB/s	3752 B/op	39 allocs/op
BenchmarkEncrypt64KBWithDirectGCM128	3000	588655 ns/op	111.33 MB/s	76328 B/op	39 allocs/op
BenchmarkEncrypt1MBWithDirectGCM128	200	9300478 ns/op	112.74 MB/s	1059370 B/op	39 allocs/op
BenchmarkEncrypt64MBWithDirectGCM128	2	589059919 ns/op	113.93 MB/s	67119712 B/op	40 allocs/op
BenchmarkEncrypt1BWithDirectCBC128	200000	9155 ns/op	0.11 MB/s	3008 B/op	48 allocs/op
BenchmarkEncrypt64BWithDirectCBC128	200000	9882 ns/op	6.48 MB/s	3312 B/op	49 allocs/op
BenchmarkEncrypt1KBWithDirectCBC128	100000	17533 ns/op	58.40 MB/s	6384 B/op	49 allocs/op
BenchmarkEncrypt64KBWithDirectCBC128	3000	536457 ns/op	122.16 MB/s	224112 B/op	49 allocs/op
BenchmarkEncrypt1MBWithDirectCBC128	200	8344933 ns/op	125.65 MB/s	3173237 B/op	49 allocs/op
BenchmarkEncrypt64MBWithDirectCBC128	2	542799030 ns/op	123.63 MB/s	201354208 B/op	51 allocs/op
BenchmarkEncrypt1BWithDirectGCM256	200000	6428 ns/op	0.16 MB/s	2632 B/op	39 allocs/op
BenchmarkEncrypt64BWithDirectGCM256	200000	6728 ns/op	9.51 MB/s	2680 B/op	39 allocs/op
BenchmarkEncrypt1KBWithDirectGCM256	100000	15343 ns/op	66.74 MB/s	3752 B/op	39 allocs/op
BenchmarkEncrypt64KBWithDirectGCM256	3000	589663 ns/op	111.14 MB/s	76328 B/op	39 allocs/op
BenchmarkEncrypt1MBWithDirectGCM256	200	9222674 ns/op	113.70 MB/s	1059370 B/op	39 allocs/op
BenchmarkEncrypt64MBWithDirectGCM256	2	585505726 ns/op	114.62 MB/s	67119712 B/op	40 allocs/op
BenchmarkEncrypt1BWithDirectCBC256	200000	9253 ns/op	0.11 MB/s	3008 B/op	48 allocs/op
BenchmarkEncrypt64BWithDirectCBC256	200000	9807 ns/op	6.53 MB/s	3312 B/op	49 allocs/op
BenchmarkEncrypt1KBWithDirectCBC256	100000	17566 ns/op	58.29 MB/s	6384 B/op	49 allocs/op
BenchmarkEncrypt64KBWithDirectCBC256	3000	534048 ns/op	122.72 MB/s	224112 B/op	49 allocs/op
BenchmarkEncrypt1MBWithDirectCBC256	200	8321683 ns/op	126.01 MB/s	3173237 B/op	49 allocs/op
BenchmarkEncrypt64MBWithDirectCBC256	2	547308969 ns/op	122.62 MB/s	201354208 B/op	51 allocs/op
BenchmarkEncrypt1BWithAESKWAndGCM128	200000	9342 ns/op	0.11 MB/s	3128 B/op	47 allocs/op
BenchmarkEncrypt64BWithAESKWAndGCM128	200000	9700 ns/op	6.60 MB/s	3176 B/op	47 allocs/op
BenchmarkEncrypt1KBWithAESKWAndGCM128	100000	17646 ns/op	58.03 MB/s	4248 B/op	47 allocs/op
BenchmarkEncrypt64KBWithAESKWAndGCM128	3000	554686 ns/op	118.15 MB/s	76824 B/op	47 allocs/op
BenchmarkEncrypt1MBWithAESKWAndGCM128	200	8641684 ns/op	121.34 MB/s	1059866 B/op	47 allocs/op
BenchmarkEncrypt64MBWithAESKWAndGCM128	2	559784808 ns/op	119.88 MB/s	67120208 B/op	48 allocs/op
BenchmarkEncrypt1BWithAESKWAndCBC256	200000	11456 ns/op	0.09 MB/s	3352 B/op	49 allocs/op
BenchmarkEncrypt64BWithAESKWAndCBC256	100000	11933 ns/op	5.36 MB/s	3400 B/op	49 allocs/op
BenchmarkEncrypt1KBWithAESKWAndCBC256	100000	20265 ns/op	50.53 MB/s	4472 B/op	49 allocs/op
BenchmarkEncrypt64KBWithAESKWAndCBC256	3000	594063 ns/op	110.32 MB/s	77048 B/op	49 allocs/op
BenchmarkEncrypt1MBWithAESKWAndCBC256	200	9230010 ns/op	113.61 MB/s	1060090 B/op	49 allocs/op
BenchmarkEncrypt64MBWithAESKWAndCBC256	2	597983574 ns/op	112.23 MB/s	67120432 B/op	50 allocs/op
BenchmarkEncrypt1BWithECDHOnP256AndGCM128	1000	2033810 ns/op	0.00 MB/s	9544 B/op	159 allocs/op
BenchmarkEncrypt64BWithECDHOnP256AndGCM128	1000	2031713 ns/op	0.03 MB/s	9597 B/op	159 allocs/op
BenchmarkEncrypt1KBWithECDHOnP256AndGCM128	1000	2043545 ns/op	0.50 MB/s	10671 B/op	159 allocs/op
BenchmarkEncrypt64KBWithECDHOnP256AndGCM128	500	2572098 ns/op	25.48 MB/s	83240 B/op	159 allocs/op
BenchmarkEncrypt1MBWithECDHOnP256AndGCM128	100	10734176 ns/op	97.69 MB/s	1066294 B/op	159 allocs/op
BenchmarkEncrypt64MBWithECDHOnP256AndGCM128	2	553348072 ns/op	121.28 MB/s	67126592 B/op	160 allocs/op
BenchmarkEncrypt1BWithECDHOnP384AndGCM128	100	12745101 ns/op	0.00 MB/s	5667299 B/op	58988 allocs/op
BenchmarkEncrypt64BWithECDHOnP384AndGCM128	100	12631938 ns/op	0.01 MB/s	5646994 B/op	58781 allocs/op
BenchmarkEncrypt1KBWithECDHOnP384AndGCM128	100	12736010 ns/op	0.08 MB/s	5671276 B/op	59023 allocs/op
BenchmarkEncrypt64KBWithECDHOnP384AndGCM128	100	13273116 ns/op	4.94 MB/s	5732568 B/op	58902 allocs/op
BenchmarkEncrypt1MBWithECDHOnP384AndGCM128	100	21666116 ns/op	48.40 MB/s	6714229 B/op	58885 allocs/op
BenchmarkEncrypt64MBWithECDHOnP384AndGCM128	2	589203147 ns/op	113.90 MB/s	72731584 B/op	58517 allocs/op
BenchmarkEncrypt1BWithECDHOnP521AndGCM128	100	22724400 ns/op	0.00 MB/s	10330404 B/op	89314 allocs/op
BenchmarkEncrypt64BWithECDHOnP521AndGCM128	50	23323938 ns/op	0.00 MB/s	10365208 B/op	89611 allocs/op
BenchmarkEncrypt1KBWithECDHOnP521AndGCM128	100	23369009 ns/op	0.04 MB/s	10339675 B/op	89366 allocs/op
BenchmarkEncrypt64KBWithECDHOnP521AndGCM128	100	23689319 ns/op	2.77 MB/s	10418313 B/op	89420 allocs/op
BenchmarkEncrypt1MBWithECDHOnP521AndGCM128	50	32499965 ns/op	32.26 MB/s	11336803 B/op	88884 allocs/op
BenchmarkEncrypt64MBWithECDHOnP521AndGCM128	2	590291252 ns/op	113.69 MB/s	77337960 B/op	88319 allocs/op
BenchmarkDecrypt1BWithOAEPAndGCM	200	6806851 ns/op	0.00 MB/s	994684 B/op	7437 allocs/op
BenchmarkDecrypt64BWithOAEPAndGCM	200	6733866 ns/op	0.01 MB/s	992361 B/op	7424 allocs/op
BenchmarkDecrypt1KBWithOAEPAndGCM	200	6614587 ns/op	0.15 MB/s	994735 B/op	7428 allocs/op
BenchmarkDecrypt64KBWithOAEPAndGCM	200	7263697 ns/op	9.02 MB/s	1058156 B/op	7420 allocs/op
BenchmarkDecrypt1MBWithOAEPAndGCM	100	15562798 ns/op	67.38 MB/s	2039794 B/op	7414 allocs/op
BenchmarkDecrypt64MBWithOAEPAndGCM	2	559648415 ns/op	119.91 MB/s	68094696 B/op	7400 allocs/op
BenchmarkDecrypt1BWithPKCSAndGCM	200	6773018 ns/op	0.00 MB/s	992507 B/op	7421 allocs/op
BenchmarkDecrypt64BWithPKCSAndGCM	200	6992753 ns/op	0.01 MB/s	993460 B/op	7425 allocs/op
BenchmarkDecrypt1KBWithPKCSAndGCM	200	6800349 ns/op	0.15 MB/s	993402 B/op	7418 allocs/op
BenchmarkDecrypt64KBWithPKCSAndGCM	200	7296990 ns/op	8.98 MB/s	1058608 B/op	7419 allocs/op
BenchmarkDecrypt1MBWithPKCSAndGCM	100	15542436 ns/op	67.47 MB/s	2040074 B/op	7407 allocs/op
BenchmarkDecrypt64MBWithPKCSAndGCM	2	558156205 ns/op	120.23 MB/s	68119552 B/op	7536 allocs/op
BenchmarkDecrypt1BWithOAEPAndCBC	200	6701219 ns/op	0.00 MB/s	994712 B/op	7435 allocs/op
BenchmarkDecrypt64BWithOAEPAndCBC	200	6636243 ns/op	0.01 MB/s	992489 B/op	7420 allocs/op
BenchmarkDecrypt1KBWithOAEPAndCBC	200	6657514 ns/op	0.15 MB/s	994128 B/op	7424 allocs/op
BenchmarkDecrypt64KBWithOAEPAndCBC	200	6948515 ns/op	9.43 MB/s	1066024 B/op	7422 allocs/op
BenchmarkDecrypt1MBWithOAEPAndCBC	100	11911074 ns/op	88.03 MB/s	2058627 B/op	7416 allocs/op
BenchmarkDecrypt64MBWithOAEPAndCBC	3	400618795 ns/op	167.51 MB/s	90486418 B/op	7482 allocs/op
BenchmarkDecrypt1BWithPKCSAndCBC	200	6678279 ns/op	0.00 MB/s	993940 B/op	7431 allocs/op
BenchmarkDecrypt64BWithPKCSAndCBC	200	6662427 ns/op	0.01 MB/s	993386 B/op	7424 allocs/op
BenchmarkDecrypt1KBWithPKCSAndCBC	200	6809190 ns/op	0.15 MB/s	997263 B/op	7446 allocs/op
BenchmarkDecrypt64KBWithPKCSAndCBC	200	7070785 ns/op	9.27 MB/s	1068240 B/op	7430 allocs/op
BenchmarkDecrypt1MBWithPKCSAndCBC	100	12009873 ns/op	87.31 MB/s	2060018 B/op	7423 allocs/op
BenchmarkDecrypt64MBWithPKCSAndCBC	3	409642644 ns/op	163.82 MB/s	90480978 B/op	7445 allocs/op
BenchmarkDecrypt1BWithDirectGCM128	300000	4623 ns/op	0.22 MB/s	1736 B/op	32 allocs/op
BenchmarkDecrypt64BWithDirectGCM128	300000	5083 ns/op	12.59 MB/s	1792 B/op	32 allocs/op
BenchmarkDecrypt1KBWithDirectGCM128	100000	13646 ns/op	75.04 MB/s	2752 B/op	32 allocs/op
BenchmarkDecrypt64KBWithDirectGCM128	3000	586645 ns/op	111.71 MB/s	67264 B/op	32 allocs/op
BenchmarkDecrypt1MBWithDirectGCM128	200	9301046 ns/op	112.74 MB/s	1050304 B/op	32 allocs/op
BenchmarkDecrypt64MBWithDirectGCM128	2	591459680 ns/op	113.46 MB/s	67110624 B/op	32 allocs/op
BenchmarkDecrypt1BWithDirectCBC128	200000	6398 ns/op	0.16 MB/s	1944 B/op	36 allocs/op
BenchmarkDecrypt64BWithDirectCBC128	200000	6951 ns/op	9.21 MB/s	2136 B/op	37 allocs/op
BenchmarkDecrypt1KBWithDirectCBC128	100000	11843 ns/op	86.46 MB/s	3096 B/op	37 allocs/op
BenchmarkDecrypt64KBWithDirectCBC128	5000	335986 ns/op	195.06 MB/s	75685 B/op	37 allocs/op
BenchmarkDecrypt1MBWithDirectCBC128	300	5220608 ns/op	200.85 MB/s	1062208 B/op	37 allocs/op
BenchmarkDecrypt64MBWithDirectCBC128	3	402232473 ns/op	166.84 MB/s	89488690 B/op	39 allocs/op
BenchmarkDecrypt1BWithDirectGCM256	300000	4623 ns/op	0.22 MB/s	1736 B/op	32 allocs/op
BenchmarkDecrypt64BWithDirectGCM256	300000	5062 ns/op	12.64 MB/s	1792 B/op	32 allocs/op
BenchmarkDecrypt1KBWithDirectGCM256	100000	13679 ns/op	74.86 MB/s	2752 B/op	32 allocs/op
BenchmarkDecrypt64KBWithDirectGCM256	2000	595367 ns/op	110.08 MB/s	67264 B/op	32 allocs/op
BenchmarkDecrypt1MBWithDirectGCM256	200	9291817 ns/op	112.85 MB/s	1050304 B/op	32 allocs/op
BenchmarkDecrypt64MBWithDirectGCM256	2	587836149 ns/op	114.16 MB/s	67110624 B/op	32 allocs/op
BenchmarkDecrypt1BWithDirectCBC256	200000	6448 ns/op	0.16 MB/s	1944 B/op	36 allocs/op
BenchmarkDecrypt64BWithDirectCBC256	200000	6906 ns/op	9.27 MB/s	2136 B/op	37 allocs/op
BenchmarkDecrypt1KBWithDirectCBC256	200000	11720 ns/op	87.37 MB/s	3096 B/op	37 allocs/op
BenchmarkDecrypt64KBWithDirectCBC256	5000	327982 ns/op	199.82 MB/s	75685 B/op	37 allocs/op
BenchmarkDecrypt1MBWithDirectCBC256	300	5173627 ns/op	202.68 MB/s	1062208 B/op	37 allocs/op
BenchmarkDecrypt64MBWithDirectCBC256	3	395953403 ns/op	169.49 MB/s	89488690 B/op	39 allocs/op
BenchmarkDecrypt1BWithAESKWAndGCM128	200000	6121 ns/op	0.16 MB/s	2200 B/op	39 allocs/op
BenchmarkDecrypt64BWithAESKWAndGCM128	200000	6498 ns/op	9.85 MB/s	2256 B/op	39 allocs/op
BenchmarkDecrypt1KBWithAESKWAndGCM128	100000	14523 ns/op	70.51 MB/s	3216 B/op	39 allocs/op
BenchmarkDecrypt64KBWithAESKWAndGCM128	3000	545609 ns/op	120.12 MB/s	67728 B/op	39 allocs/op
BenchmarkDecrypt1MBWithAESKWAndGCM128	200	8749088 ns/op	119.85 MB/s	1050768 B/op	39 allocs/op
BenchmarkDecrypt64MBWithAESKWAndGCM128	2	551432594 ns/op	121.70 MB/s	67111088 B/op	39 allocs/op
BenchmarkDecrypt1BWithAESKWAndCBC256	200000	7227 ns/op	0.14 MB/s	2408 B/op	41 allocs/op
BenchmarkDecrypt64BWithAESKWAndCBC256	200000	7552 ns/op	8.47 MB/s	2464 B/op	41 allocs/op
BenchmarkDecrypt1KBWithAESKWAndCBC256	100000	16171 ns/op	63.32 MB/s	3424 B/op	41 allocs/op
BenchmarkDecrypt64KBWithAESKWAndCBC256	3000	588466 ns/op	111.37 MB/s	67936 B/op	41 allocs/op
BenchmarkDecrypt1MBWithAESKWAndCBC256	200	9235014 ns/op	113.54 MB/s	1050976 B/op	41 allocs/op
BenchmarkDecrypt64MBWithAESKWAndCBC256	2	601283259 ns/op	111.61 MB/s	67111296 B/op	41 allocs/op
BenchmarkDecrypt1BWithECDHOnP256AndGCM128	1000	1500135 ns/op	0.00 MB/s	6440 B/op	121 allocs/op
BenchmarkDecrypt64BWithECDHOnP256AndGCM128	1000	1490829 ns/op	0.04 MB/s	6496 B/op	121 allocs/op
BenchmarkDecrypt1KBWithECDHOnP256AndGCM128	1000	1492366 ns/op	0.69 MB/s	7456 B/op	121 allocs/op
BenchmarkDecrypt64KBWithECDHOnP256AndGCM128	1000	2032864 ns/op	32.24 MB/s	71872 B/op	120 allocs/op
BenchmarkDecrypt1MBWithECDHOnP256AndGCM128	100	10083317 ns/op	103.99 MB/s	1054912 B/op	120 allocs/op
BenchmarkDecrypt64MBWithECDHOnP256AndGCM128	2	567913503 ns/op	118.17 MB/s	67115344 B/op	122 allocs/op
BenchmarkDecrypt1BWithECDHOnP384AndGCM128	200	6150085 ns/op	0.00 MB/s	2742691 B/op	28535 allocs/op
BenchmarkDecrypt64BWithECDHOnP384AndGCM128	200	6173224 ns/op	0.01 MB/s	2745948 B/op	28627 allocs/op
BenchmarkDecrypt1KBWithECDHOnP384AndGCM128	200	6219548 ns/op	0.16 MB/s	2742284 B/op	28543 allocs/op
BenchmarkDecrypt64KBWithECDHOnP384AndGCM128	200	6708501 ns/op	9.77 MB/s	2805499 B/op	28515 allocs/op
BenchmarkDecrypt1MBWithECDHOnP384AndGCM128	100	14888397 ns/op	70.43 MB/s	3788460 B/op	28511 allocs/op
BenchmarkDecrypt64MBWithECDHOnP384AndGCM128	2	554409101 ns/op	121.05 MB/s	69852424 B/op	28569 allocs/op
BenchmarkDecrypt1BWithECDHOnP521AndGCM128	100	11526405 ns/op	0.00 MB/s	5183103 B/op	44762 allocs/op
BenchmarkDecrypt64BWithECDHOnP521AndGCM128	100	11684190 ns/op	0.01 MB/s	5183759 B/op	44776 allocs/op
BenchmarkDecrypt1KBWithECDHOnP521AndGCM128	100	11820154 ns/op	0.09 MB/s	5190198 B/op	44926 allocs/op
BenchmarkDecrypt64KBWithECDHOnP521AndGCM128	100	12358636 ns/op	5.30 MB/s	5254134 B/op	44882 allocs/op
BenchmarkDecrypt1MBWithECDHOnP521AndGCM128	100	20894700 ns/op	50.18 MB/s	6227144 B/op	44727 allocs/op
BenchmarkDecrypt64MBWithECDHOnP521AndGCM128	2	579692130 ns/op	115.77 MB/s	72291416 B/op
```

Also, for comparison: `go get github.com/benburkert/lockbox && go test -run=XXX -bench=. -benchmem github.com/benburkert/lockbox` :wink: