Created
May 20, 2014 16:07
-
-
Save c9s/28504e4f63599daf8646 to your computer and use it in GitHub Desktop.
libr3 benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Time::HiRes qw(time); | |
my %routes = ( | |
"/foo/bar/baz" => 0, | |
"/foo/bar/qux" => 1, | |
"/foo/bar/quux" => 2, | |
"/foo/bar/corge" => 3, | |
"/foo/bar/grault" => 4, | |
"/foo/bar/garply" => 5, | |
"/foo/baz/bar" => 6, | |
"/foo/baz/qux" => 7, | |
"/foo/baz/quux" => 8, | |
"/foo/baz/corge" => 9, | |
"/foo/baz/grault" => 10, | |
"/foo/baz/garply" => 11, | |
"/foo/qux/bar" => 12, | |
"/foo/qux/baz" => 13, | |
"/foo/qux/quux" => 14, | |
"/foo/qux/corge" => 15, | |
"/foo/qux/grault" => 16, | |
"/foo/qux/garply" => 17, | |
"/foo/quux/bar" => 18, | |
"/foo/quux/baz" => 19, | |
"/foo/quux/qux" => 20, | |
"/foo/quux/corge" => 21, | |
"/foo/quux/grault" => 22, | |
"/foo/quux/garply" => 23, | |
"/foo/corge/bar" => 24, | |
"/foo/corge/baz" => 25, | |
"/foo/corge/qux" => 26, | |
"/foo/corge/quux" => 27, | |
"/foo/corge/grault" => 28, | |
"/foo/corge/garply" => 29, | |
"/foo/grault/bar" => 30, | |
"/foo/grault/baz" => 31, | |
"/foo/grault/qux" => 32, | |
"/foo/grault/quux" => 33, | |
"/foo/grault/corge" => 34, | |
"/foo/grault/garply" => 35, | |
"/foo/garply/bar" => 36, | |
"/foo/garply/baz" => 37, | |
"/foo/garply/qux" => 38, | |
"/foo/garply/quux" => 39, | |
"/foo/garply/corge" => 40, | |
"/foo/garply/grault" => 41, | |
"/bar/foo/baz" => 42, | |
"/bar/foo/qux" => 43, | |
"/bar/foo/quux" => 44, | |
"/bar/foo/corge" => 45, | |
"/bar/foo/grault" => 46, | |
"/bar/foo/garply" => 47, | |
"/bar/baz/foo" => 48, | |
"/bar/baz/qux" => 49, | |
"/bar/baz/quux" => 50, | |
"/bar/baz/corge" => 51, | |
"/bar/baz/grault" => 52, | |
"/bar/baz/garply" => 53, | |
"/bar/qux/foo" => 54, | |
"/bar/qux/baz" => 55, | |
"/bar/qux/quux" => 56, | |
"/bar/qux/corge" => 57, | |
"/bar/qux/grault" => 58, | |
"/bar/qux/garply" => 59, | |
"/bar/quux/foo" => 60, | |
"/bar/quux/baz" => 61, | |
"/bar/quux/qux" => 62, | |
"/bar/quux/corge" => 63, | |
"/bar/quux/grault" => 64, | |
"/bar/quux/garply" => 65, | |
"/bar/corge/foo" => 66, | |
"/bar/corge/baz" => 67, | |
"/bar/corge/qux" => 68, | |
"/bar/corge/quux" => 69, | |
"/bar/corge/grault" => 70, | |
"/bar/corge/garply" => 71, | |
"/bar/grault/foo" => 72, | |
"/bar/grault/baz" => 73, | |
"/bar/grault/qux" => 74, | |
"/bar/grault/quux" => 75, | |
"/bar/grault/corge" => 76, | |
"/bar/grault/garply" => 77, | |
"/bar/garply/foo" => 78, | |
"/bar/garply/baz" => 79, | |
"/bar/garply/qux" => 80, | |
"/bar/garply/quux" => 81, | |
"/bar/garply/corge" => 82, | |
"/bar/garply/grault" => 83, | |
"/baz/foo/bar" => 84, | |
"/baz/foo/qux" => 85, | |
"/baz/foo/quux" => 86, | |
"/baz/foo/corge" => 87, | |
"/baz/foo/grault" => 88, | |
"/baz/foo/garply" => 89, | |
"/baz/bar/foo" => 90, | |
"/baz/bar/qux" => 91, | |
"/baz/bar/quux" => 92, | |
"/baz/bar/corge" => 93, | |
"/baz/bar/grault" => 94, | |
"/baz/bar/garply" => 95, | |
"/baz/qux/foo" => 96, | |
"/baz/qux/bar" => 97, | |
"/baz/qux/quux" => 98, | |
"/baz/qux/corge" => 99, | |
"/baz/qux/grault" => 100, | |
"/baz/qux/garply" => 101, | |
"/baz/quux/foo" => 102, | |
"/baz/quux/bar" => 103, | |
"/baz/quux/qux" => 104, | |
"/baz/quux/corge" => 105, | |
"/baz/quux/grault" => 106, | |
"/baz/quux/garply" => 107, | |
"/baz/corge/foo" => 108, | |
"/baz/corge/bar" => 109, | |
"/baz/corge/qux" => 110, | |
"/baz/corge/quux" => 111, | |
"/baz/corge/grault" => 112, | |
"/baz/corge/garply" => 113, | |
"/baz/grault/foo" => 114, | |
"/baz/grault/bar" => 115, | |
"/baz/grault/qux" => 116, | |
"/baz/grault/quux" => 117, | |
"/baz/grault/corge" => 118, | |
"/baz/grault/garply" => 119, | |
"/baz/garply/foo" => 120, | |
"/baz/garply/bar" => 121, | |
"/baz/garply/qux" => 122, | |
"/baz/garply/quux" => 123, | |
"/baz/garply/corge" => 124, | |
"/baz/garply/grault" => 125, | |
"/qux/foo/bar" => 126, | |
"/qux/foo/baz" => 127, | |
"/qux/foo/quux" => 128, | |
"/qux/foo/corge" => 129, | |
"/qux/foo/grault" => 130, | |
"/qux/foo/garply" => 131, | |
"/qux/bar/foo" => 132, | |
"/qux/bar/baz" => 133, | |
"/qux/bar/quux" => 134, | |
"/qux/bar/corge" => 135, | |
"/qux/bar/grault" => 136, | |
"/qux/bar/garply" => 137, | |
"/qux/baz/foo" => 138, | |
"/qux/baz/bar" => 139, | |
"/qux/baz/quux" => 140, | |
"/qux/baz/corge" => 141, | |
"/qux/baz/grault" => 142, | |
"/qux/baz/garply" => 143, | |
"/qux/quux/foo" => 144, | |
"/qux/quux/bar" => 145, | |
"/qux/quux/baz" => 146, | |
"/qux/quux/corge" => 147, | |
"/qux/quux/grault" => 148, | |
"/qux/quux/garply" => 149, | |
"/qux/corge/foo" => 150, | |
"/qux/corge/bar" => 151, | |
"/qux/corge/baz" => 152, | |
"/qux/corge/quux" => 153, | |
"/qux/corge/grault" => 154, | |
"/qux/corge/garply" => 155, | |
"/qux/grault/foo" => 156, | |
"/qux/grault/bar" => 157, | |
"/qux/grault/baz" => 158, | |
"/qux/grault/quux" => 159, | |
"/qux/grault/corge" => 160, | |
"/qux/grault/garply" => 161, | |
"/qux/garply/foo" => 162, | |
"/qux/garply/bar" => 163, | |
"/qux/garply/baz" => 164, | |
"/qux/garply/quux" => 165, | |
"/qux/garply/corge" => 166, | |
"/qux/garply/grault" => 167, | |
"/quux/foo/bar" => 168, | |
"/quux/foo/baz" => 169, | |
"/quux/foo/qux" => 170, | |
"/quux/foo/corge" => 171, | |
"/quux/foo/grault" => 172, | |
"/quux/foo/garply" => 173, | |
"/quux/bar/foo" => 174, | |
"/quux/bar/baz" => 175, | |
"/quux/bar/qux" => 176, | |
"/quux/bar/corge" => 177, | |
"/quux/bar/grault" => 178, | |
"/quux/bar/garply" => 179, | |
"/quux/baz/foo" => 180, | |
"/quux/baz/bar" => 181, | |
"/quux/baz/qux" => 182, | |
"/quux/baz/corge" => 183, | |
"/quux/baz/grault" => 184, | |
"/quux/baz/garply" => 185, | |
"/quux/qux/foo" => 186, | |
"/quux/qux/bar" => 187, | |
"/quux/qux/baz" => 188, | |
"/quux/qux/corge" => 189, | |
"/quux/qux/grault" => 190, | |
"/quux/qux/garply" => 191, | |
"/quux/corge/foo" => 192, | |
"/quux/corge/bar" => 193, | |
"/quux/corge/baz" => 194, | |
"/quux/corge/qux" => 195, | |
"/quux/corge/grault" => 196, | |
"/quux/corge/garply" => 197, | |
"/quux/grault/foo" => 198, | |
"/quux/grault/bar" => 199, | |
"/quux/grault/baz" => 200, | |
"/quux/grault/qux" => 201, | |
"/quux/grault/corge" => 202, | |
"/quux/grault/garply" => 203, | |
"/quux/garply/foo" => 204, | |
"/quux/garply/bar" => 205, | |
"/quux/garply/baz" => 206, | |
"/quux/garply/qux" => 207, | |
"/quux/garply/corge" => 208, | |
"/quux/garply/grault" => 209, | |
"/corge/foo/bar" => 210, | |
"/corge/foo/baz" => 211, | |
"/corge/foo/qux" => 212, | |
"/corge/foo/quux" => 213, | |
"/corge/foo/grault" => 214, | |
"/corge/foo/garply" => 215, | |
"/corge/bar/foo" => 216, | |
"/corge/bar/baz" => 217, | |
"/corge/bar/qux" => 218, | |
"/corge/bar/quux" => 219, | |
"/corge/bar/grault" => 220, | |
"/corge/bar/garply" => 221, | |
"/corge/baz/foo" => 222, | |
"/corge/baz/bar" => 223, | |
"/corge/baz/qux" => 224, | |
"/corge/baz/quux" => 225, | |
"/corge/baz/grault" => 226, | |
"/corge/baz/garply" => 227, | |
"/corge/qux/foo" => 228, | |
"/corge/qux/bar" => 229, | |
"/corge/qux/baz" => 230, | |
"/corge/qux/quux" => 231, | |
"/corge/qux/grault" => 232, | |
"/corge/qux/garply" => 233, | |
"/corge/quux/foo" => 234, | |
"/corge/quux/bar" => 235, | |
"/corge/quux/baz" => 236, | |
"/corge/quux/qux" => 237, | |
"/corge/quux/grault" => 238, | |
"/corge/quux/garply" => 239, | |
"/corge/grault/foo" => 240, | |
"/corge/grault/bar" => 241, | |
"/corge/grault/baz" => 242, | |
"/corge/grault/qux" => 243, | |
"/corge/grault/quux" => 244, | |
"/corge/grault/garply" => 245, | |
"/corge/garply/foo" => 246, | |
"/corge/garply/bar" => 247, | |
"/corge/garply/baz" => 248, | |
"/corge/garply/qux" => 249, | |
"/corge/garply/quux" => 250, | |
"/corge/garply/grault" => 251, | |
"/grault/foo/bar" => 252, | |
"/grault/foo/baz" => 253, | |
"/grault/foo/qux" => 254, | |
"/grault/foo/quux" => 255, | |
"/grault/foo/corge" => 256, | |
"/grault/foo/garply" => 257, | |
"/grault/bar/foo" => 258, | |
"/grault/bar/baz" => 259, | |
"/grault/bar/qux" => 260, | |
"/grault/bar/quux" => 261, | |
"/grault/bar/corge" => 262, | |
"/grault/bar/garply" => 263, | |
"/grault/baz/foo" => 264, | |
"/grault/baz/bar" => 265, | |
"/grault/baz/qux" => 266, | |
"/grault/baz/quux" => 267, | |
"/grault/baz/corge" => 268, | |
"/grault/baz/garply" => 269, | |
"/grault/qux/foo" => 270, | |
"/grault/qux/bar" => 271, | |
"/grault/qux/baz" => 272, | |
"/grault/qux/quux" => 273, | |
"/grault/qux/corge" => 274, | |
"/grault/qux/garply" => 275, | |
"/grault/quux/foo" => 276, | |
"/grault/quux/bar" => 277, | |
"/grault/quux/baz" => 278, | |
"/grault/quux/qux" => 279, | |
"/grault/quux/corge" => 280, | |
"/grault/quux/garply" => 281, | |
"/grault/corge/foo" => 282, | |
"/grault/corge/bar" => 283, | |
"/grault/corge/baz" => 284, | |
"/grault/corge/qux" => 285, | |
"/grault/corge/quux" => 286, | |
"/grault/corge/garply" => 287, | |
"/grault/garply/foo" => 288, | |
"/grault/garply/bar" => 289, | |
"/grault/garply/baz" => 290, | |
"/grault/garply/qux" => 291, | |
"/grault/garply/quux" => 292, | |
"/grault/garply/corge" => 293, | |
"/garply/foo/bar" => 294, | |
"/garply/foo/baz" => 295, | |
"/garply/foo/qux" => 296, | |
"/garply/foo/quux" => 297, | |
"/garply/foo/corge" => 298, | |
"/garply/foo/grault" => 299, | |
"/garply/bar/foo" => 300, | |
"/garply/bar/baz" => 301, | |
"/garply/bar/qux" => 302, | |
"/garply/bar/quux" => 303, | |
"/garply/bar/corge" => 304, | |
"/garply/bar/grault" => 305, | |
"/garply/baz/foo" => 306, | |
"/garply/baz/bar" => 307, | |
"/garply/baz/qux" => 308, | |
"/garply/baz/quux" => 309, | |
"/garply/baz/corge" => 310, | |
"/garply/baz/grault" => 311, | |
"/garply/qux/foo" => 312, | |
"/garply/qux/bar" => 313, | |
"/garply/qux/baz" => 314, | |
"/garply/qux/quux" => 315, | |
"/garply/qux/corge" => 316, | |
"/garply/qux/grault" => 317, | |
"/garply/quux/foo" => 318, | |
"/garply/quux/bar" => 319, | |
"/garply/quux/baz" => 320, | |
"/garply/quux/qux" => 321, | |
"/garply/quux/corge" => 322, | |
"/garply/quux/grault" => 323, | |
"/garply/corge/foo" => 324, | |
"/garply/corge/bar" => 325, | |
"/garply/corge/baz" => 326, | |
"/garply/corge/qux" => 327, | |
"/garply/corge/quux" => 328, | |
"/garply/corge/grault" => 329, | |
"/garply/grault/foo" => 330, | |
"/garply/grault/bar" => 331, | |
"/garply/grault/baz" => 332, | |
"/garply/grault/qux" => 333, | |
"/garply/grault/quux" => 334, | |
"/garply/grault/corge" => 335, | |
); | |
use Router::R3; | |
#Router::R3::test(); | |
my $t = Router::R3->new(\%routes); | |
my $s = time(); | |
my $N = 500000; | |
for ( 1..$N ) { | |
$t->match('/corge/quux/bar'); | |
} | |
my $d = time() - $s; | |
print ($N / $d); | |
print " i/s\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment