The results from this are:[3] [3] We’re leaving out some redundant parts of the output that would make it harder to read here. Benchmark: timing 400 iterations of loop, loopset, set, undef… loop: 21 wallclock secs (21.07 usr + 0.01 sys = 21.08 CPU) loopset: 21 wallclock secs (21.03 usr + 0.00 sys = 21.03 CPU) set: 17 wallclock secs (16.44 usr + 0.01 sys = 16.45 CPU) undef: 8 wallclock secs ( 7.58 usr + 0.00 sys = 7.58 CPU) Note that the tests are run in alphabetical order by name, not necessarily in the order they were specified; that’s because they’re hash keys, and hashes have no innate ordering. If the code you’re testing does little or no I/O, the figures you should compare are the CPU times; the wall clock figures can be skewed if the machine is busy servicing other processes. If you’re testing different code snippets that do lots of I/O, and do that I/O differently, then you have more of a problem. You have no choice except to compare wall clock figures, but you must make sure that the system isn’t interrupted by some other large process while you are benchmarking. So keep an eye on it with top or the equivalent to see what else is running during your benchmark. We can see that there’s no difference in setting an element to undefor 1, but there is a significant improvement in setting all the elements at once to 1 with a hash slice and an even bigger improvement in using a hash slice to set them all to undef (presumably because we aren’t taking the time to form a large list on the right-hand side). This tidbit can come in handy when we’re using a hash just to test for existence; we can set the keys using a hash slice without having to set the values and later test for existence with exists. Well, wait a minute. Might there be a performance hit from using the existsfunction rather than testing the truth of the hash value? Why guess when we can benchmark it? use Benchmark; my %h; @h{map int rand 1000, 1..100} = (1) x 100; timethese (1000000, { exists => ‘$x++ if exists $h{int rand 1000}’, true => ‘$x++ if $h{int rand 1000}’, }); We first fill the hash with up to 100 integer keys randomly chosen from the range 0 to 999, and then we compare the operation of testing an element for existence with testing one for truth. (The $x++ is just to give Perl something to do so we don’t have to worry about whether a smart optimizer might decide to elide our code altogether.) The results are
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services