in reply to Could SHA encode faster than MD5?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Could SHA encode faster than MD5?
by haukex (Archbishop) on Jun 23, 2020 at 20:18 UTC | |
memoize('Digest::MD5::add'); memoize('Digest::MD5::hexdigest'); No, this is plain wrong in several ways. As per the Memoize documentation:
Memoizing add breaks the object's functionality. Memoizing hexdigest is wrong because the method normally modifies the object's state, plus, since it is a method that is normally only called once per object, Memoizing it isn't actually useful because the first argument to a method is a reference to the object, i.e. it will be different on every call and therefore the return value won't actually be cached across different objects.
Update: Oh, and your tests prove that adding Memoize slowed execution by a factor of roughly 2.2 and 13, respectively: #Benchmarking... #Digest::MD5 2.55 #Benchmark: running Digest::MD5, Digest::MD5::new for at least 1 CPU seconds... #Digest::MD5: -1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU) @ 138871.96/s (n=154009) #Digest::MD5::new: 1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU) @ 69872.97/s (n=77559) # #Benchmarking with Memoize... #Digest::MD5 2.55 #Benchmark: running Digest::MD5, Digest::MD5::new for at least 1 CPU seconds... #Digest::MD5: 1 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 61895.11/s (n=69632) #Digest::MD5::new: 1 wallclock secs ( 1.06 usr + 0.03 sys = 1.09 CPU) @ 5227.61/s (n=5719) | [reply] [d/l] [select] |