"Steven Lumos" <slumos / yahoo.com> schrieb im Newsbeitrag
news:86wu94f8pk.fsf / bitty.lumos.us...
>
> I have a (really) big data structure, which looks like:
>
>   Features = [
>     ["feature", ["parent1", "parent2"], {:C1 => [0.0, (7 more)], :C2 =>
....}],
>     ...a LOT more (like 2500) lines...
>   ]
>
> I was initially using (shudder) XML for storage, but as the structure
> developed, we literally had to choose between dumping XML or dumping
> Ruby.  I thought about other generic methods but ended up settling on
> writing out the Ruby representation of the structure and loading it
> with require.  What I'm currently using is exactly like the above but
> with the constant wrapped in a module.
>
> 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
>

Strange.  Normally I would have suggested a combination of Marshal and
load: The dump is used if it is newer than the Ruby file, otherwise the
ruby file is loaded and dumped.  This should yield quite fast loading
speed while maintaining simple editibility.  (Is that an English word?
:-))

However, you might want to reconsider your data structure.  Maybe there is
a more efficient way of handling this.  You could use path names as
feature keys into a single Hash for example:

Features = {
  "feature.parent1" => true,
  "feature.parent2" => true,
  # ...
}

Of course this is just a guess since I don't know the data at hand.

Kind regards

    robert