From: "T. Onoma" Date: 2003-12-11T10:56:36+09:00 Subject: Re: [Q] Fast loading of BIG data structures On Thursday 11 December 2003 02:27 am, Steven Lumos wrote: > My question is: Is there an even faster way to load a big structure > than this? > > My first thought was to use Marshal, but I was surprised to find that > Marshal.load takes about twice as long as require: > > $ ruby -v > ruby 1.8.0 (2003-08-04) [sparc-solaris2.8] > $ time ruby -e "require 'network'" > real 0m3.431s > user 0m3.080s > sys 0m0.200s > $ time ruby -e "File.open('network.dump') {|f| Marshal.load(f)}" > real 0m7.321s > user 0m6.880s > sys 0m0.170s Curious. What kind of machine are you running this on? These times seem a bit slow in general. I'm also wondering how Yaml would compare. Are you running ruby 1.8+? If so try using to_yaml and dumping the result to a file, and then reload. Simple example to help if you're not familiar with Yaml: # save in yaml format require 'yaml' require 'network' File.open('network.yaml','w'){|f| f << Features.to_yaml} You might want to look at the yaml file at this point, it is rather readable. Then try # load yaml file require 'yaml' Features = Yaml::load(File.open('network.yaml')) And see what kind of times you get. T.