UriBenchmark.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2016-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <folly/Uri.h>
  17. #include <folly/Benchmark.h>
  18. #include <folly/init/Init.h>
  19. using namespace folly;
  20. /**
  21. * Result of benchmark varies by the complexity of query.
  22. * ============================================================================
  23. * folly/test/UriTest.cpp relative time/iter iters/s
  24. * ============================================================================
  25. * init_uri_simple 4.88us 204.80K
  26. * init_uri_simple_with_query_parsing 22.46us 44.52K
  27. * init_uri_complex 5.92us 168.85K
  28. * init_uri_complex_with_query_parsing 48.70us 20.53K
  29. * ============================================================================
  30. */
  31. BENCHMARK(init_uri_simple, iters) {
  32. const fbstring s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
  33. for (size_t i = 0; i < iters; ++i) {
  34. Uri u(s);
  35. }
  36. }
  37. BENCHMARK(init_uri_simple_with_query_parsing, iters) {
  38. const fbstring s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
  39. for (size_t i = 0; i < iters; ++i) {
  40. Uri u(s);
  41. u.getQueryParams();
  42. }
  43. }
  44. BENCHMARK(init_uri_complex, iters) {
  45. const fbstring s(
  46. "https://mock.example.com/farm/track.php?TmOxQUDF=uSmTS_VwhjKnh_JME&DI"
  47. "h=fbbN&GRsoIm=bGshjaUqavZxQai&UMT=36k18N4dn21&3U=CD8o4A4497W152j6m0V%14"
  48. "%57&Hy=t%05mpr.80JUZ7ne_%23zS8DcA%0qc_%291ymamz096%11Zfb3r%09ZqPD%311ZX"
  49. "tqJd600ot&5U96U-Rh-VZ=-D_6-9xKYj%1gW6b43s1B9-j21P0oUW5-t46G4kgt&ezgj=mcW"
  50. "TTQ.c&Oh=%2PblUfuC%7C997048884827569%03xnyJ%2L1pi7irBioQ6D4r7nNHNdo6v7Y%"
  51. "84aurnSJ%2wCFePHMlGZmIHGfCe7392_lImWsSvN&sBeNN=Nf%80yOE%6X10M64F4gG197aX"
  52. "R2B4g2533x235A0i4e%57%58uWB%04Erw.60&VMS4=Ek_%02GC0Pkx%6Ov_%207WICUz007%"
  53. "04nYX8N%46zzpv%999h&KGmBt988y=q4P57C-Dh-Nz-x_7-5oPxz%1gz3N03t6c7-R67N4DT"
  54. "Y6-f98W1&Lts&%02dOty%8eEYEnLz4yexQQLnL4MGU2JFn3OcmXcatBcabZgBdDdy67hdgW"
  55. "tYn4");
  56. for (size_t i = 0; i < iters; ++i) {
  57. Uri u(s);
  58. }
  59. }
  60. BENCHMARK(init_uri_complex_with_query_parsing, iters) {
  61. const fbstring s(
  62. "https://mock.example.com/farm/track.php?TmOxQUDF=uSmTS_VwhjKnh_JME&DI"
  63. "h=fbbN&GRsoIm=bGshjaUqavZxQai&UMT=36k18N4dn21&3U=CD8o4A4497W152j6m0V%14"
  64. "%57&Hy=t%05mpr.80JUZ7ne_%23zS8DcA%0qc_%291ymamz096%11Zfb3r%09ZqPD%311ZX"
  65. "tqJd600ot&5U96U-Rh-VZ=-D_6-9xKYj%1gW6b43s1B9-j21P0oUW5-t46G4kgt&ezgj=mcW"
  66. "TTQ.c&Oh=%2PblUfuC%7C997048884827569%03xnyJ%2L1pi7irBioQ6D4r7nNHNdo6v7Y%"
  67. "84aurnSJ%2wCFePHMlGZmIHGfCe7392_lImWsSvN&sBeNN=Nf%80yOE%6X10M64F4gG197aX"
  68. "R2B4g2533x235A0i4e%57%58uWB%04Erw.60&VMS4=Ek_%02GC0Pkx%6Ov_%207WICUz007%"
  69. "04nYX8N%46zzpv%999h&KGmBt988y=q4P57C-Dh-Nz-x_7-5oPxz%1gz3N03t6c7-R67N4DT"
  70. "Y6-f98W1&Lts&%02dOty%8eEYEnLz4yexQQLnL4MGU2JFn3OcmXcatBcabZgBdDdy67hdgW"
  71. "tYn4");
  72. for (size_t i = 0; i < iters; ++i) {
  73. Uri u(s);
  74. u.getQueryParams();
  75. }
  76. }
  77. int main(int argc, char** argv) {
  78. folly::init(&argc, &argv);
  79. folly::runBenchmarks();
  80. return 0;
  81. }