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

Optimize asComponentString method #2

Merged
merged 1 commit into from
Apr 23, 2017
Merged

Optimize asComponentString method #2

merged 1 commit into from
Apr 23, 2017

Conversation

thibaultmeyer
Copy link
Contributor

The method asComponentString has been rewrite. String.format has been removed and the method was now around 10 times faster.

Benchmarked with a 100K iteration with the following code:

for (int j = 0; j < 3; ++j) {
    startTime = System.currentTimeMillis();
    for (int i = 0; i < 100000; ++i) {
        asComponentString_OLD(data);
    }
    endTime = System.currentTimeMillis();
    LOG.info("asComponentString_OLD -> {}ms", endTime - startTime);
}
for (int j = 0; j < 3; ++j) {
    startTime = System.currentTimeMillis();
    for (int i = 0; i < 100000; ++i) {
        asComponentString_NEW(data);
    }
    endTime = System.currentTimeMillis();
    LOG.info("asComponentString_NEW -> {}ms", endTime - startTime);
}
[2017-04-22 21:04:42] INFO - MainEntry - asComponentString_OLD -> 508ms
[2017-04-22 21:04:44] INFO - MainEntry - asComponentString_OLD -> 220ms
[2017-04-22 21:04:47] INFO - MainEntry - asComponentString_OLD -> 220ms
[2017-04-22 21:04:47] INFO - MainEntry - asComponentString_NEW -> 57ms
[2017-04-22 21:04:47] INFO - MainEntry - asComponentString_NEW -> 29ms
[2017-04-22 21:04:47] INFO - MainEntry - asComponentString_NEW -> 27ms

By removing String.format usage, the method
asComponentString is now around 10 times faster.

Signed-off-by: Thibault Meyer <meyer.thibault@gmail.com>
@charithe charithe merged commit b74ee8b into charithe:master Apr 23, 2017
@charithe
Copy link
Owner

Thanks!

@thibaultmeyer
Copy link
Contributor Author

thibaultmeyer commented Apr 23, 2017

@charithe, Any chance to have the new version published on Maven repository (like the version 1.0.0 - http://mvnrepository.com/artifact/com.github.charithe/flake4j) ?

Maybe it could be nice to edit README to specify that your implementation generate a 128 bits Flake ID.

Sincerely.

@charithe
Copy link
Owner

Done. Released version 1.0.1.

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

Successfully merging this pull request may close these issues.

None yet

2 participants