Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fasten DecodedInstruction #38

Closed
vbmacher opened this issue Mar 10, 2017 · 3 comments
Closed

Fasten DecodedInstruction #38

vbmacher opened this issue Mar 10, 2017 · 3 comments
Milestone

Comments

@vbmacher
Copy link
Collaborator

vbmacher commented Mar 10, 2017

Instead of HashMaps use TreeMaps

vbmacher pushed a commit that referenced this issue Mar 10, 2017
@vbmacher
Copy link
Collaborator Author

This need to be measured. HashMaps are supposed to be faster than TreeMaps... https://www.baeldung.com/java-treemap-vs-hashmap

@vbmacher
Copy link
Collaborator Author

I have measured the two implementations, using the following test:

    @Test
    public void testPerformance() {
        DecodedInstruction instruction = new DecodedInstruction();
        HDecodedInstruction hinstruction = new HDecodedInstruction();

        long start = System.nanoTime();
        for (int i = 0; i < 2000000; i++) {
            instruction.add(i, "SSSS" + i, i);
        }
        long end = System.nanoTime() - start;

        System.out.println("TreeMaps: " + TimeUnit.NANOSECONDS.toMillis(end));

        long hstart = System.nanoTime();
        for (int i = 0; i < 2000000; i++) {
            hinstruction.add(i, "SSSS" + i, i);
        }
        long hend = System.nanoTime() - hstart;

        System.out.println("HashMaps: " + TimeUnit.NANOSECONDS.toMillis(hend));
    }

Where DecodedInstruction uses TreeMap, and HDecodedInsruction uses HashMap. The results are:

TreeMaps: 1580
HashMaps: 1007

So I will revert back the HashMaps

@vbmacher
Copy link
Collaborator Author

I don't know how it can be fastened, so I will close the issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant