Created
January 25, 2024 09:10
-
-
Save kuboon/eaf6d89b5477c69dc2d800ed2aa6dcfb to your computer and use it in GitHub Desktop.
deserialize_bench.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'json' | |
require 'active_support/notifications' | |
require 'active_support/cache' | |
array = (1..1000).map { rand } | |
TIMES = 1000 | |
Benchmark.bmbm do |x| | |
cache = ActiveSupport::Cache::FileStore.new("./tmp/cache") | |
cache.write("array", array) | |
x.report("ActiveSupport::Cache::FileStore") { TIMES.times { cache.read("array") } } | |
json = array.to_json; | |
x.report("JSON.parse") { TIMES.times { JSON.parse(json) } } | |
dump = Marshal.dump(array); | |
x.report("Marshal") { TIMES.times { Marshal.load(dump) } } | |
end | |
__END__ | |
Rehearsal ------------------------------------------------------------------- | |
ActiveSupport::Cache::FileStore 0.919142 0.003467 0.922609 ( 0.922660) | |
JSON.parse 0.698001 0.083742 0.781743 ( 0.781774) | |
Marshal 0.759887 0.000063 0.759950 ( 0.759991) | |
---------------------------------------------------------- total: 2.464302sec | |
user system total real | |
ActiveSupport::Cache::FileStore 0.894407 0.003877 0.898284 ( 0.898354) | |
JSON.parse 0.717439 0.035830 0.753269 ( 0.753309) | |
Marshal 0.781801 0.000000 0.781801 ( 0.781836) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment