[cost] Model Collection's containsAll

Reviewed By: skcho

Differential Revision: D26100472

fbshipit-source-id: d59c0c860
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent 0a517db238
commit 802dce02d1

@ -48,6 +48,12 @@ module BoundsOf (Container : CostUtils.S) = struct
let log_n = logarithmic_length exp ~of_function cost_model_env mem ~ret in let log_n = logarithmic_length exp ~of_function cost_model_env mem ~ret in
let n = linear_length exp ~of_function cost_model_env mem ~ret in let n = linear_length exp ~of_function cost_model_env mem ~ret in
BasicCost.mult n log_n BasicCost.mult n log_n
let op_on_two_lengths exp1 exp2 ~f cost_model_env ~ret mem ~of_function =
let n = linear_length exp1 ~of_function cost_model_env mem ~ret in
let m = linear_length exp2 ~of_function cost_model_env mem ~ret in
f n m
end end
module IntHashMap = struct module IntHashMap = struct
@ -282,6 +288,10 @@ module Call = struct
; +PatternMatch.Java.implements_collection ; +PatternMatch.Java.implements_collection
&:: "contains" <>$ capt_exp &:: "contains" <>$ capt_exp
$+...$--> BoundsOfCollection.linear_length ~of_function:"Collection.contains" $+...$--> BoundsOfCollection.linear_length ~of_function:"Collection.contains"
; +PatternMatch.Java.implements_collection
&:: "containsAll" <>$ capt_exp $+ capt_exp
$+...$--> BoundsOfCollection.op_on_two_lengths ~f:BasicCost.mult
~of_function:"Collection.containsAll"
; +PatternMatch.Java.implements_collections ; +PatternMatch.Java.implements_collections
&:: "binarySearch" <>$ capt_exp &:: "binarySearch" <>$ capt_exp
$+...$--> BoundsOfCollection.logarithmic_length ~of_function:"Collections.binarySearch" $+...$--> BoundsOfCollection.logarithmic_length ~of_function:"Collections.binarySearch"

@ -104,6 +104,11 @@ public class CollectionTest {
for (int i = 0; i < set.size(); i++) {} for (int i = 0; i < set.size(); i++) {}
} }
// O(|keyMap| x |coll|)
void containsAll_quadratic(HashMap<Integer, String> keyMap, Collection<String> coll) {
keyMap.values().containsAll(coll);
}
void containsNull_linear(HashMap<Integer, String> keyMap) { void containsNull_linear(HashMap<Integer, String> keyMap) {
keyMap.values().contains(null); keyMap.values().contains(null);
} }

@ -99,6 +99,7 @@ codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.<i
codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.valueOf(java.lang.String):CollectionTest$MyEnumType, 6, OnUIThread:false, [] codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.valueOf(java.lang.String):CollectionTest$MyEnumType, 6, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.values():CollectionTest$MyEnumType[], 6, OnUIThread:false, [] codetoanalyze/java/performance/CollectionTest.java, CollectionTest$MyEnumType.values():CollectionTest$MyEnumType[], 6, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.<init>(), 2, OnUIThread:false, [] codetoanalyze/java/performance/CollectionTest.java, CollectionTest.<init>(), 2, OnUIThread:false, []
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.containsAll_quadratic(java.util.HashMap,java.util.Collection):void, 6 + coll.length × keyMap.length, OnUIThread:false, [{keyMap.length},Modeled call to Collection.containsAll,{coll.length},Modeled call to Collection.containsAll]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.containsNull_linear(java.util.HashMap):void, 5 + keyMap.length, OnUIThread:false, [{keyMap.length},Modeled call to Collection.contains] codetoanalyze/java/performance/CollectionTest.java, CollectionTest.containsNull_linear(java.util.HashMap):void, 5 + keyMap.length, OnUIThread:false, [{keyMap.length},Modeled call to Collection.contains]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.ensure_call(CollectionTest$MyCollection):void, 9 + 5 ⋅ list.length, OnUIThread:false, [{list.length},Call to void CollectionTest.iterate_over_mycollection(CollectionTest$MyCollection),Loop] codetoanalyze/java/performance/CollectionTest.java, CollectionTest.ensure_call(CollectionTest$MyCollection):void, 9 + 5 ⋅ list.length, OnUIThread:false, [{list.length},Call to void CollectionTest.iterate_over_mycollection(CollectionTest$MyCollection),Loop]
codetoanalyze/java/performance/CollectionTest.java, CollectionTest.immutable_set_of_constant():void, 9, OnUIThread:false, [] codetoanalyze/java/performance/CollectionTest.java, CollectionTest.immutable_set_of_constant():void, 9, OnUIThread:false, []

Loading…
Cancel
Save