Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC encoding/json.IndentWriter implementation #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

flimzy
Copy link
Owner

@flimzy flimzy commented Aug 19, 2019

This adds some Benchmarks for the existing Indent function, against the existing indent test inputs. A typical run:

BenchmarkIndentExample1-2       20000000               116 ns/op           8.56 MB/s          64 B/op          1 allocs/op
BenchmarkIndentExample2-2       10000000               194 ns/op          10.30 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample3-2       10000000               180 ns/op          11.10 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample4-2        5000000               323 ns/op          18.56 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample5-2       10000000               261 ns/op          11.49 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample6-2        5000000               365 ns/op          19.13 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7-2        5000000               321 ns/op          21.76 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7b-2       1000000              1004 ns/op         696.72 MB/s         880 B/op          8 allocs/op

Then it adds streaming support, and adds a new exported method, IndentWriter, which wraps an io.Writer, and indents the stream, as documented. Benchmark results virtually identical (within expected bounds for running tests on a VM), with the addition of a new set of tests for the streaming functionality:

BenchmarkIndentExample1-2               10000000               139 ns/op           7.19 MB/s          64 B/op          1 allocs/op
BenchmarkIndentExample2-2               10000000               189 ns/op          10.58 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample3-2               10000000               204 ns/op           9.79 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample4-2                5000000               330 ns/op          18.18 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample5-2                5000000               276 ns/op          10.84 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample6-2                3000000               409 ns/op          17.09 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7-2                5000000               342 ns/op          20.42 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7b-2               1000000              1165 ns/op         600.74 MB/s         880 B/op          8 allocs/op
BenchmarkIndentStreamExample1-2          5000000               323 ns/op           3.09 MB/s         152 B/op          3 allocs/op
BenchmarkIndentStreamExample2-2          5000000               367 ns/op           5.44 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample3-2          5000000               363 ns/op           5.50 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample4-2          3000000               496 ns/op          12.08 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample5-2          3000000               455 ns/op           6.58 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample6-2          3000000               640 ns/op          10.94 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample7-2          3000000               520 ns/op          13.45 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample7b-2         1000000              1293 ns/op         541.27 MB/s         960 B/op          9 allocs/op

flimzy added 2 commits August 19, 2019 18:47
BEFORE:
BenchmarkIndentExample1-2       20000000               116 ns/op           8.56 MB/s          64 B/op          1 allocs/op
BenchmarkIndentExample2-2       10000000               194 ns/op          10.30 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample3-2       10000000               180 ns/op          11.10 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample4-2        5000000               323 ns/op          18.56 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample5-2       10000000               261 ns/op          11.49 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample6-2        5000000               365 ns/op          19.13 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7-2        5000000               321 ns/op          21.76 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7b-2       1000000              1004 ns/op         696.72 MB/s         880 B/op          8 allocs/op

AFTER:
BenchmarkIndentExample1-2               10000000               139 ns/op           7.19 MB/s          64 B/op          1 allocs/op
BenchmarkIndentExample2-2               10000000               189 ns/op          10.58 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample3-2               10000000               204 ns/op           9.79 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample4-2                5000000               330 ns/op          18.18 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample5-2                5000000               276 ns/op          10.84 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample6-2                3000000               409 ns/op          17.09 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7-2                5000000               342 ns/op          20.42 MB/s          72 B/op          2 allocs/op
BenchmarkIndentExample7b-2               1000000              1165 ns/op         600.74 MB/s         880 B/op          8 allocs/op
BenchmarkIndentStreamExample1-2          5000000               323 ns/op           3.09 MB/s         152 B/op          3 allocs/op
BenchmarkIndentStreamExample2-2          5000000               367 ns/op           5.44 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample3-2          5000000               363 ns/op           5.50 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample4-2          3000000               496 ns/op          12.08 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample5-2          3000000               455 ns/op           6.58 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample6-2          3000000               640 ns/op          10.94 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample7-2          3000000               520 ns/op          13.45 MB/s         160 B/op          4 allocs/op
BenchmarkIndentStreamExample7b-2         1000000              1293 ns/op         541.27 MB/s         960 B/op          9 allocs/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant