Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9262921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:27:38+00:00 2026-06-18T13:27:38+00:00

I am trying to measure how much time each thread takes in inserting to

  • 0

I am trying to measure how much time each thread takes in inserting to database. I have captured all those performance numbers in a ConcurrentHashMap named map like how much time each thread is taking in inserting. In that concurrent hash map it will be something like this.

Key- 10
Value- 2

So that means, 2 Calls came back in 10 ms. Another example below

Key - 20
Value -1

which means, 1 Call came back in 20 ms.

And that map will contain lot more data means lot more key value pair.

So now I am trying to do something like below by using the same map above, that means I need to iterate the above map to get the below numbers in that particular range. Is that possible to do?

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 code that I thought of 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++) {
                 // Not sure what I am supposed to do here?
    }
    System.out.println();
}

Can anyone help me here?

Update:-

My map sample value-

{31=3, 48=1, 33=1, 30=12, 43=1, 38=1, 32=1}

It means total call was 3+1+1+12+1+1+1 = 20 by adding value from the map

And out of that I need to figure out the above scenario 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 have tried with the below suggestion-

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 is showing only 7 calls. Anything wrong I did? This is the output 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 calls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T13:27:39+00:00Added an answer on June 18, 2026 at 1:27 pm

    Anticipating the need to easily redefine bucket size (and indeed the number of buckets you aggregate into) I propose:

        Map<Integer, Integer> values = new HashMap<Integer, Integer>();
    
        int[] definition = {0, 20, 40, 60, 80, 100};
        int[] buckets = new int[definition.length];
    
        for (int time : values.keySet()) {
            for (int i=definition.length-1; i>=0; i--) {
                if (time >= definition[i]) {
                    buckets[i] += values.get(time);
                    break;
                }
            }
        }
        for (int i=0; i<definition.length; i++) {
            String period = "";
            if (i == definition.length-1) {
                period = "greater than " + definition[i] + "ms";
            } else {
                period = "between " +
                          (definition[i]+1) +
                          " and " +
                          definition[i+1] + "ms";
            }
            System.out.println(buckets[i] + " came back " + period);
        }
    

    Configurability is managed by changing definition. I used the following code to test this:

        Random rnd = new Random();
        for (int i=0; i<1000; i++) {
            int time = rnd.nextInt(121);
            Integer calls = values.get(time);
            if (calls == null) {
                calls = Integer.valueOf(0);
            }
            calls += 1;
            values.put(time, calls);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to measure how much time each thread takes in inserting to
I am trying to check how much time does a function takes to execute
I'm trying to measure how long it takes read then encrypt some data (independently).
I am trying to measure the performance increase of inlining an accessor into a
I'm trying to create a module/class in node.js to measure asynchronous execution time but
So I was trying to measure the time two different algorithm implementations took to
I am trying to measure the estimated cycle lengths it takes my computer to
I'm trying to measure the time difference between 2 signals on the parallel port,
Is there a way to measure the average time it takes my code to
I am trying to measure the execution time taken by some functions in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.