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

Don't use StringIO in benchmarks #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MatmaRex
Copy link

StringIO seems to be absurdly slow, on the order of ten times slower
than writing to a real IO (e.g. a file). Writing the output to the
null device (/dev/null on Linux, NUL on Windows, etc.) should be much more
reasonable for performance comparison.

Results from benchmark/encode.rb on my machine, using StringIO.new
and File.open(File::NULL, 'w'):

StringIO Null device
Yajl::Encoder#encode (to an IO) 3.085176 0.683039
Yajl::Encoder#encode (to a String) 0.526030 0.544032
JSON.generate 1.380079 1.432082
Psych.to_json 10.271588 10.016573
Psych::JSON::Stream 9.238529 4.949283
ActiveSupport::JSON.encode 10.817619 10.233585

StringIO seems to be absurdly slow, on the order of ten times slower
than writing to a real IO (e.g. a file). Writing the output to the
null device (/dev/null on Linux, NUL on Windows, etc.) should be much more
reasonable for performance comparison.

Results from `benchmark/encode.rb` on my machine, using `StringIO.new`
and `File.open(File::NULL, 'w')`:

|                                      |  StringIO | Null device |
| ------------------------------------ | --------- | ----------- |
| Yajl::Encoder#encode (to an IO)      |  3.085176 |    0.683039 |
| Yajl::Encoder#encode (to a String)   |  0.526030 |    0.544032 |
| JSON.generate                        |  1.380079 |    1.432082 |
| Psych.to_json                        | 10.271588 |   10.016573 |
| Psych::JSON::Stream                  |  9.238529 |    4.949283 |
| ActiveSupport::JSON.encode           | 10.817619 |   10.233585 |
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.

None yet

1 participant