Skip to content

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.

1 participant