I am trying to measure how long each thread takes when pasting into a database. I wrote down all these performance numbers on a map called ConcurrentHashMap , for example, how long each thread takes to insert. In this parallel hash map, it will be something like this.
Key- 10 Value- 2
Thus, this means that 2 calls returned after 10 ms. Another example below
Key - 20 Value -1
which means that 1 call returned after 20 ms.
And this map will contain a lot more data, which means more than a pair of key values.
So now I'm trying to do something like below using the same map above, which means I need to iterate the map above to get the numbers below in this specific range. Can this be done?
How many calls(X number) came back in between 1 and 20 ms How many calls(X number) came back in between 20 and 40 ms How many calls(X number) came back in between 40 and 60 ms How many calls(X number) came back in between 60 and 80 ms How many calls(X number) came back in between 80 and 100 ms How many calls(X number) came back after 100 ms
Some kind of code that I was thinking about initially.
SortedSet<Long> keys = new TreeSet<Long>(map.keySet()); for (Long key : keys) { System.out.print(key + " : "); for (int i = 0; i < map.get(key); i++) {
Can someone help me here?
Update: -
The value of my card is
{31=3, 48=1, 33=1, 30=12, 43=1, 38=1, 32=1}
This means that the general call was 3+1+1+12+1+1+1 = 20 , adding value from map
And from this I need to find out that the above script means something like this
How many calls(X number) came back in between 1 and 20 ms How many calls(X number) came back in between 20 and 40 ms How many calls(X number) came back in between 40 and 60 ms How many calls(X number) came back in between 60 and 80 ms How many calls(X number) came back in between 80 and 100 ms How many calls(X number) came back after 100 ms
Below is my code that I tried with the sentence below -
private static void drawHistogram (Map Map) {
int counter[] = new int[6]; for (Integer key : map.keySet()) { System.out.println("" + key); // add sample int idx = key / 20; idx = Math.min(idx, counter.length - 1); counter[idx]++; } for (int i = 0; i < counter.length; i++) { System.out.println(counter[i] + " came back in between " + i * 20 + " and " + (i + 1) * 20 + " ms"); }
}
As you can see, I have 20 calls made, but this only shows 7 calls. Is something wrong with me? This is the result I got -
0 came back in between 0 and 20 ms 5 came back in between 20 and 40 ms 2 came back in between 40 and 60 ms 0 came back in between 60 and 80 ms 0 came back in between 80 and 100 ms 0 came back in between 100 and 120 ms
which shows only 7 calls. But there are 20 challenges.