Skip to content

Instantly share code, notes, and snippets.

@tdakkota
Last active October 26, 2022 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdakkota/9ef35ce009425a23662108e537b970e2 to your computer and use it in GitHub Desktop.
Save tdakkota/9ef35ce009425a23662108e537b970e2 to your computer and use it in GitHub Desktop.
ogen vs chi routing benchmark
name time/op
Router/GithubStatic/ogen-4 18.7ns ± 3%
Router/GithubStatic/chi-4 146ns ± 2%
Router/GithubStatic/echo-4 73.7ns ± 9%
Router/GithubParam/ogen-4 34.0ns ± 3%
Router/GithubParam/chi-4 251ns ± 3%
Router/GithubParam/echo-4 118ns ± 2%
Router/GithubAll/ogen-4 56.6µs ± 3%
Router/GithubAll/chi-4 323µs ± 3%
Router/GithubAll/echo-4 173µs ± 4%
name alloc/op
Router/GithubStatic/ogen-4 0.00B
Router/GithubStatic/chi-4 0.00B
Router/GithubStatic/echo-4 0.00B
Router/GithubParam/ogen-4 0.00B
Router/GithubParam/chi-4 0.00B
Router/GithubParam/echo-4 0.00B
Router/GithubAll/ogen-4 0.00B
Router/GithubAll/chi-4 0.00B
Router/GithubAll/echo-4 0.00B
name allocs/op
Router/GithubStatic/ogen-4 0.00
Router/GithubStatic/chi-4 0.00
Router/GithubStatic/echo-4 0.00
Router/GithubParam/ogen-4 0.00
Router/GithubParam/chi-4 0.00
Router/GithubParam/echo-4 0.00
Router/GithubAll/ogen-4 0.00
Router/GithubAll/chi-4 0.00
Router/GithubAll/echo-4 0.00
goos: windows
goarch: amd64
pkg: github.com/ogen-go/ogen
cpu: Intel(R) Core(TM) i3-3250 CPU @ 3.50GHz
BenchmarkRouter
BenchmarkRouter/GithubStatic
BenchmarkRouter/GithubStatic/ogen
BenchmarkRouter/GithubStatic/ogen-4 63177844 18.64 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66691119 18.66 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66692972 18.35 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63181171 18.83 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66686672 18.61 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66688154 18.95 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63179508 18.95 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 54564055 18.54 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66924698 18.76 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63180838 18.39 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63188491 18.70 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66693714 18.55 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63177512 19.00 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66692972 18.44 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63183832 18.22 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 70580346 18.35 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63178177 19.25 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66693714 18.75 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 63173521 18.62 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 60026410 19.67 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 70622715 18.75 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66692232 18.52 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66688154 18.51 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 66690378 18.36 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/ogen-4 54174848 19.14 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi
BenchmarkRouter/GithubStatic/chi-4 8110803 146.9 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8336024 144.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8216385 147.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8278608 144.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8335706 145.2 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8335682 144.9 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8278624 147.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8336042 145.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8166008 144.9 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8310099 149.2 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8306941 145.9 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8278630 145.3 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8278225 145.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8258223 166.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8271867 145.0 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8163553 144.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 6975843 145.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8264815 144.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8221857 145.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8336151 148.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8363499 145.0 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8360923 145.3 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8218850 145.2 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8249877 148.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/chi-4 8162382 146.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo
BenchmarkRouter/GithubStatic/echo-4 16670857 71.68 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16904527 79.01 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16221805 69.50 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 15389566 70.62 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 15005007 71.87 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 15898208 77.80 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16221696 68.90 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16222968 72.31 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16672038 70.89 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16221674 76.07 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 17150280 73.48 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 15666327 70.84 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16005462 76.69 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 15794938 77.11 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16906837 76.70 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16111750 80.32 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16908814 72.12 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16907074 75.98 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16241763 71.39 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16005590 75.87 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 17146874 75.71 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 17165097 69.13 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16221433 73.42 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 16432682 72.35 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubStatic/echo-4 13956750 71.77 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam
BenchmarkRouter/GithubParam/ogen
BenchmarkRouter/GithubParam/ogen-4 36794691 33.98 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35306266 33.96 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35307097 33.81 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35817259 34.51 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35306370 34.55 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35308240 33.67 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 36375871 34.24 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35369745 33.62 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 36376202 34.26 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 33810530 35.03 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 34297375 34.45 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35305954 42.93 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 34297081 44.73 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 36375760 36.44 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 36374768 33.74 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35306162 33.99 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35305435 33.78 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35831912 34.14 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35305332 33.95 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 36376423 33.88 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35305954 34.08 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 34297081 34.21 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35306682 33.54 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 35307097 33.64 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/ogen-4 36375540 33.71 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi
BenchmarkRouter/GithubParam/chi-4 4812772 254.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4840314 248.0 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4763305 248.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4820815 253.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4835880 249.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4596861 249.3 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4840315 251.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4651627 259.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4786394 254.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4838078 251.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4839111 253.2 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4794909 248.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4830511 249.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4818622 254.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4828806 247.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4818288 248.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4840308 252.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4801587 249.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4839817 248.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4801591 249.3 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4409532 252.0 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4763470 247.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4810442 248.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4820726 254.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/chi-4 4825246 248.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo
BenchmarkRouter/GithubParam/echo-4 10159116 117.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10254691 118.9 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10172775 117.0 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10172973 116.9 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10259961 117.2 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10259628 119.4 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10062765 118.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10172223 117.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10251021 118.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 8562052 117.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10003326 117.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 9839412 119.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10259162 121.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10259206 117.7 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10003341 118.3 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10172938 117.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10216261 121.2 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10261180 117.0 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10215486 118.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10333059 119.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10259172 117.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10172792 120.8 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10254244 117.1 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10320129 120.5 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubParam/echo-4 10338855 117.6 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll
BenchmarkRouter/GithubAll/ogen
BenchmarkRouter/GithubAll/ogen-4 21212 56064 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21283 57263 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21392 56204 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21098 56188 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20167 57208 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21315 56358 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20950 56266 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20119 56227 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21604 56511 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21270 57792 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20542 56916 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20980 55812 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21004 58291 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21648 56272 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20805 69609 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 17202 68921 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20748 56571 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21448 58140 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21124 56300 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21358 55889 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21489 57977 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21460 55656 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21561 56550 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 20160 56360 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/ogen-4 21114 55867 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi
BenchmarkRouter/GithubAll/chi-4 3429 320869 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3750 330254 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 317996 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3750 320410 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3627 319996 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 330153 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3637 319063 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3687 321366 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 319732 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3672 332248 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3637 321747 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3530 320190 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3750 323764 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3637 331711 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3622 319734 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3702 327506 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3734 321133 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 330468 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 318660 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 320211 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3750 319185 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3751 328718 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3738 320886 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3714 322781 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/chi-4 3637 319598 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo
BenchmarkRouter/GithubAll/echo-4 7060 179602 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 170298 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6668 170271 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 205940 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6303 178929 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6670 171656 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 170540 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6640 175837 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 172532 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7011 171334 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6668 170386 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6996 176144 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7058 171362 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6668 171162 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7029 171566 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 176969 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 172649 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7077 171377 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7029 171161 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6668 178322 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6615 172148 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7060 172810 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 7059 170566 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6756 174274 ns/op 0 B/op 0 allocs/op
BenchmarkRouter/GithubAll/echo-4 6824 170925 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/ogen-go/ogen 319.232s
package ogen_test
import (
_ "embed"
"net/http"
"net/url"
"regexp"
"testing"
"github.com/go-chi/chi/v5"
"github.com/labstack/echo/v4"
"github.com/ogen-go/ogen"
api "github.com/ogen-go/ogen/examples/ex_github"
)
//go:embed _testdata/examples/api.github.com.json
var githubSpec []byte
func forEachOp(item *ogen.PathItem, cb func(method string, op *ogen.Operation)) {
for _, c := range []struct {
method string
op *ogen.Operation
}{
{"GET", item.Get},
{"PUT", item.Put},
{"POST", item.Post},
{"DELETE", item.Delete},
{"OPTIONS", item.Options},
{"HEAD", item.Head},
{"PATCH", item.Patch},
{"TRACE", item.Trace},
} {
if c.op != nil {
cb(c.method, c.op)
}
}
}
var (
noopHandler http.HandlerFunc = func(http.ResponseWriter, *http.Request) {}
paramsRegexp = regexp.MustCompile(`\{(?P<name>\w*)}`)
)
func colonParamsPath(p string) string {
return paramsRegexp.ReplaceAllString(p, ":$1")
}
func setupChi(r chi.Router, spec *ogen.Spec) {
for path, item := range spec.Paths {
forEachOp(item, func(method string, op *ogen.Operation) {
r.Method(method, path, noopHandler)
})
}
}
func setupEcho(r *echo.Echo, spec *ogen.Spec) {
for path, item := range spec.Paths {
forEachOp(item, func(method string, op *ogen.Operation) {
r.Add(method, colonParamsPath(path), echo.WrapHandler(noopHandler))
})
}
}
func BenchmarkRouter(b *testing.B) {
spec, err := ogen.Parse(githubSpec)
if err != nil {
b.Fatal(err)
}
benchOgen := func(route string) func(b *testing.B) {
return func(b *testing.B) {
s := api.Server{}
b.ReportAllocs()
b.ResetTimer()
var (
ok bool
)
for i := 0; i < b.N; i++ {
_, ok = s.FindRoute("GET", route)
}
if !ok {
b.Fail()
}
}
}
benchChi := func(route string) func(b *testing.B) {
return func(b *testing.B) {
r := chi.NewRouter()
setupChi(r, spec)
b.ReportAllocs()
b.ResetTimer()
var (
ok bool
rctx = chi.NewRouteContext()
)
for i := 0; i < b.N; i++ {
rctx.Reset()
ok = r.Match(rctx, "GET", route)
}
if !ok {
b.Fail()
}
}
}
benchEcho := func(route string) func(b *testing.B) {
return func(b *testing.B) {
r := echo.New()
setupEcho(r, spec)
req, _ := http.NewRequest("GET", route, nil)
b.ReportAllocs()
b.ResetTimer()
var ctx = r.NewContext(req, nil)
for i := 0; i < b.N; i++ {
ctx.Reset(req, nil)
r.Router().Find("GET", route, ctx)
}
}
}
benches := []struct {
name string
route string
}{
{"GithubStatic", "/user/repos"},
{"GithubParam", "/repos/julienschmidt/httprouter"},
}
for _, bench := range benches {
b.Run(bench.name, func(b *testing.B) {
b.Run("ogen", benchOgen(bench.route))
b.Run("chi", benchChi(bench.route))
b.Run("echo", benchEcho(bench.route))
})
}
type route struct {
method string
path string
url *url.URL
}
var (
routes []route
)
for path, item := range spec.Paths {
// Un-parametrize path.
path := paramsRegexp.ReplaceAllString(path, "$1")
forEachOp(item, func(method string, _ *ogen.Operation) {
u, err := url.Parse(path)
if err != nil {
b.Fatalf("path %q: %v", path, err)
}
routes = append(routes, route{method, path, u})
})
}
b.Run("GithubAll", func(b *testing.B) {
b.Run("ogen", func(b *testing.B) {
s := api.Server{}
b.ReportAllocs()
b.ResetTimer()
var (
ok bool
)
for i := 0; i < b.N; i++ {
for _, r := range routes {
_, ok = s.FindRoute(r.method, r.path)
}
}
if !ok {
b.Fail()
}
})
b.Run("chi", func(b *testing.B) {
r := chi.NewRouter()
setupChi(r, spec)
b.ReportAllocs()
b.ResetTimer()
var (
ok bool
rctx = chi.NewRouteContext()
)
for i := 0; i < b.N; i++ {
for _, route := range routes {
rctx.Reset()
ok = r.Match(rctx, route.method, route.path)
}
}
if !ok {
b.Fail()
}
})
b.Run("echo", func(b *testing.B) {
r := echo.New()
setupEcho(r, spec)
req, _ := http.NewRequest("GET", "/", nil)
b.ReportAllocs()
b.ResetTimer()
var (
rctx = r.NewContext(req, nil)
)
for i := 0; i < b.N; i++ {
for _, route := range routes {
req.Method = route.method
req.URL = route.url
rctx.Reset(req, nil)
r.Router().Find(route.method, route.path, rctx)
}
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment