Skip to content

Commit

Permalink
Fix factor values for newer versions of clojure.core.cache
Browse files Browse the repository at this point in the history
Newer versions of clojure.core.cache for the TTL type use a different
implementation that is way faster than it used to be. So the factors
configured in the tests are no longer sensible and need to be
adjusted.
  • Loading branch information
iarenaza committed Apr 7, 2021
1 parent ca3348f commit ebdf588
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions test/coop/magnet/core_cache_comparison_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,36 @@
(deftest comparative-performance
(testing "How well my TTLCache implementation performs against the standard core.cache one"
(testing "Insertion and expiry"
(let [factor (implementation-speed-compare #(cache/miss % :c 42))]
(println "With 0 out of 5,000 cache items being expired, adding an item to my TTLCache is " factor " times faster than the core.cache one")
(is (> factor 100)))
(let [factor (implementation-speed-compare-with-1pc-eviction #(cache/miss % :c 42))]
(println "With 50 out of 5,000 cache items being expired, adding an item to my TTLCache is " factor " times faster than the core.cache one")
(is (> factor 3)))

(let [factor (implementation-speed-compare-with-5pc-eviction #(cache/miss % :c 42))]
(println "With 250 out of 5,000 cache items being expired, adding an item to my TTLCache is " factor " times faster than the core.cache one")
(is (> factor 0.5)))
(let [factor (implementation-speed-compare-with-99pc-eviction #(cache/miss % :c 42))]
(println "With 4950 out of 5,000 cache items being expired, adding an item to my TTLCache is " (/ 1 factor) " times SLOWER than the core.cache one")
(is (> factor 0.01))))
(let [factor (implementation-speed-compare #(cache/miss % :c 42))]
(println "With 0 out of 5,000 cache items being expired, adding an item to my TTLCache is " (/ 1 factor) " times SLOWER than the core.cache one")
(is (> factor 0.3)))
(let [factor (implementation-speed-compare-with-1pc-eviction #(cache/miss % :c 42))]
(println "With 50 out of 5,000 cache items being expired, adding an item to my TTLCache is " (/ 1 factor) " times SLOWER than the core.cache one")
(is (> factor 0.20)))

(let [factor (implementation-speed-compare-with-5pc-eviction #(cache/miss % :c 42))]
(println "With 250 out of 5,000 cache items being expired, adding an item to my TTLCache is " (/ 1 factor) " times SLOWER than the core.cache one")
(is (> factor 0.2)))
(let [factor (implementation-speed-compare-with-99pc-eviction #(cache/miss % :c 42))]
(println "With 4950 out of 5,000 cache items being expired, adding an item to my TTLCache is " (/ 1 factor) " times SLOWER than the core.cache one")
(is (> factor 0.01))))
(testing "Lookup performance"
(let [factor (implementation-speed-compare #(cache/lookup % 1))]
(println "With a 5,000-entry cache, looking an item up in my TTLCache is " factor " times faster than the core.cache one")
(is (> factor 0.95))))

(testing "Manual eviction performance"
(let [factor (implementation-speed-compare #(cache/evict % 1))]
(println "With a 5,000-entry cache, removing an item from my TTLCache is " factor " times faster than the core.cache one")
(is (> factor 1.2))))))
(let [factor (implementation-speed-compare #(cache/evict % 1))]
(println "With a 5,000-entry cache, removing an item from my TTLCache is " (/ 1 factor) " times SLOWER than the core.cache one")
(is (> factor 0.35))))))

;; Cost of new insertion

(deftest new-insertion-complexity
(testing "core.cache's TTLCache has O(n) insertion/expiry"
(let [factor (complexity-compare #(cache/miss % :c 42))]
(println "core.cache's TTLCache: adding an item to a cache with 5,000 entries takes " factor "longer than one with 1,000 entries")
(is (> 6 factor 4))))
(is (> 2 factor 0.5))))
(testing "My TTLCache has O(log n) insertion/expiry"
(let [factor (my-complexity-compare #(cache/miss % :c 42))]
(println "My TTLCache: adding an item to a cache with 5,000 entries takes " factor "longer than one with 1,000 entries")
Expand Down

0 comments on commit ebdf588

Please sign in to comment.