Last active
January 2, 2016 02:39
-
-
Save klaplume/8238704 to your computer and use it in GitHub Desktop.
Snippet that show the speed increase with (Guava) memoized Supplier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testGuavaSuppliers() throws InterruptedException | |
{ | |
Supplier<Dummy> s = Suppliers.memoize(new Supplier<Dummy>() | |
{ | |
@Override | |
public Dummy get() | |
{ | |
return Dummy.foo; | |
} | |
}); | |
Dummy dummy; | |
DateTime before, after; | |
for (int i = 0; i < 10; i++) | |
{ | |
before = DateTime.now(); | |
dummy = s.get(); | |
after = DateTime.now(); | |
System.out.println("Took: " + (after.getMillis() - before.getMillis()) + "ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment