Skip to main content
100%

Sample example demonstrating usage of Stopwatch API of Google Guava.

✓ Published0🌍 Public
PP7h
Last edited Jan 29, 2014
Created on Jan 29, 2014

This example shows how to measure elapsed time in a Java program using the Stopwatch API from Google Guava. It creates a started Stopwatch, pauses execution for a random number of milliseconds via `Thread.sleep`, then stops the timer and prints the total duration. The code demonstrates querying elapsed time in nanoseconds, microseconds, and milliseconds using `stopwatch.elapsed(TimeUnit.*)`. The essential API calls are `Stopwatch.createStarted()`, `stopwatch.stop()`, and `stopwatch.elapsed()`, with the output displayed through standard `System.out.println` statements.

AI-generated description

Similar vizzes