in reply to Benchmark on deserializing data
1- b() is faster than a() because the extra @ary. When benchmarking very fast operations, the overhead of creating variables is not negligible. Besides that, in a() you created a %hash on each iteration of the benchmark, in b() you are reusing %hash_b (forgotten the 'my'?)
2- Same as above... you are not doing the same thing. In c() a %hash is created on each iteration, in d() a global %hash_d is used. If a 'my' is added before %hash_d, then d() is faster than c()
3- Well... Storable is slower than split (from my experience, I can tell you that split is very very fast), so... why use Storable?
- Is less code, faster to write because that, and you don't need to test, debug or document it yourself.
- Is safer. For example, your example fails if the data contains '|'. And if you add escape sequences decoding, how much faster will still be split?
- Later you can change the serialized structure without updtaing the serializer and deserializer.
- Is not so slow, is no near half slow than split based code. The following sub is faster than a():
sub { my $hash_e = thaw($storable_serialized ); } # and then use $hash_e->{'2'}
Is easier, bah :-) Anyway, you probably will end spending more time fetching the data from the DB than deserializing it.
Hope this helps, José
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Benchmark on deserializing data
by shift8 (Novice) on Apr 27, 2007 at 03:11 UTC | |
|
Re^2: Benchmark on deserializing data
by RL (Monk) on Apr 27, 2007 at 16:33 UTC |