java - Method performance on Android -
i have method should find number of appearances of following words combination in array. method re-written in java c# code i've made performs 50 times slower makes me think don't know in java internals translate it.
this java code:
private map<string, long> weightwords(map<sentence, long> wordswithweight) { map<string, long> newwordswithweight = new hashmap(); (map.entry<sentence, long> item : wordswithweight.entryset()) { string title = item.getkey().gettitle().tolowercase(); string[] split = title.split("-"); string goodname = title.replace(split[0].trim() + " - ", ""); if (title.contains(split[0].trim() + " - ")) { goodname = title.replace(split[0].trim() + " - ", ""); } else if (title.contains(split[0].trim() + "- ")) { goodname = title.replace(split[0].trim() + "- ", ""); } string[] strings = goodname.split(" "); string fullstring = ""; (string s : strings) { if (!s.isempty()) { fullstring += s + " "; string currentstring = fullstring.trim(); long counter = 0l; (map.entry<sentence, long> wordentry : wordswithweight.entryset()) { { if (wordentry.getkey().gettitle().tolowercase().trim().contains(currentstring)) counter++; } } if (!newwordswithweight.containskey(s)) newwordswithweight.put(s, counter); } } } return utils.sortbyvalue(newwordswithweight); }
in code run n*n on same entry set named 'wordswithweight', , on each iteration call tolowercase() , trim(). can prepare entry set before , remove tolowercase() , trim() calls on each iteration.this should increase performance.
Comments
Post a Comment