Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2.4) 2) I get 115001, which i expect is an index error and that i will survive without the precision.
- real 0m15.719s
- user 0m0.015s
- sys 0m0.000s
- 3)
- class Memoizer2
- count: 615646
- real 0m20.986s
- user 0m0.000s
- sys 0m0.000s
- We get such a high count since there is a very high chance of duplicate work, since the result is only
- put in the cache after we have computed the result. In this case, it's much slower than synchronized actually,
- but almost all of the threads does the expensive computation, which the synchronization method is relieved off, so that is why its slower.
- 4) class Memoizer3
- count: 132918
- real 0m17.939s
- user 0m0.015s
- sys 0m0.000s
- In this case we have much better results, reducing the need to call f by a factor of 10. However,
- unlucky timing will still result in that some threads will do the same work twice. For this solution
- to work, we need atomicity.
- 5)
- class Memoizer4
- 115001
- real 0m17.586s
- user 0m0.015s
- sys 0m0.000s
- With Memoizer 4, i would have expected that we got under the synchronized method, and i'm not sure why it is not the case.
- However, what we see from the number of counts, is that we are now eliminating double computations, such that the computation will only be done once.
- This is with the use of atomicity that we lacked in Memoizer 3. It is still now rarely possible for two futures to be created wastefully, but
- the computation is the expensive part, not the memory.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement