Skip to content

Instantly share code, notes, and snippets.

@klaplume
Last active January 2, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klaplume/8238704 to your computer and use it in GitHub Desktop.
Save klaplume/8238704 to your computer and use it in GitHub Desktop.
Snippet that show the speed increase with (Guava) memoized Supplier
@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