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 8160555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:16:40+00:00 2026-06-06T18:16:40+00:00

I associate a key to a hash map for 10000000 time. Here’s the Java

  • 0

I associate a key to a hash map for 10000000 time. Here’s the Java code and output:

import java.util.HashMap;

public class TestMap {
    public static void main(String[] args) {
        HashMap<Integer, Integer> mp = new HashMap<Integer, Integer>();
        long  start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            mp.put(1, 1);
        }
        long end = System.currentTimeMillis();
        System.out.println("Elapsed time: " + (end - start) + " msecs");
    }
}


$ javac TestMap.java && java -cp . TestMap
Elapsed time: 38 msecs

And then I call java from clojure in REPL:

user=> (import java.util.HashMap)
java.util.HashMap
user=> (def mp (HashMap.))
#'user/mp
user=>  (time (dotimes [n 10000000] (.put mp 1 1)))
"Elapsed time: 10024.797 msecs"
nil

Both code do the same thing, but the clojure version runs exstreamly slow!!

What’s the problem?

  • 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-06T18:16:42+00:00Added an answer on June 6, 2026 at 6:16 pm

    add type hint is better:

    user> (import 'java.util.HashMap)
    java.util.HashMap
    user> (def mp (HashMap.))
    #'user/mp
    user> (time (dotimes [n 10000000] (.put mp 1 1)))
    "Elapsed time: 13932.248126 msecs"
    nil
    user> (time (dotimes [n 10000000] (.put ^HashMap mp 1 1)))
    "Elapsed time: 117.915992 msecs"
    nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.util.*; public class HashMapExample { public static class WriteOnceMap<K, V> extends HashMap<K, V>
I have a key value pair in Hashmap in Java, I am traversing Map
Is there some implementation of java.util.Map that does not uses HashCode? I have the
I have a java.util.HashMap object m (a return value from a call to Java
I'm writing a simple hash map class: template <class K, class V> class HashMap;
Possible Duplicate: Java Hashmap: How to get key from value? I know that a
We use the ASP.NET profile subsystem to associate key-value pairs of information with users.
How do I associate a Key-Value pair with textBox autoComplete extender in a way
I have a hash table where the vast majority of accesses at run-time follow
So, I'd like to use a java map where the keys are an object...but

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.