Skip to content

Support custom TimeUnits in StopWatch #25803

@ImSejin

Description

@ImSejin

I use spring-core:5.2.9.RELEASE.

When I invoke StopWatch#prettyPrint,

StopWatch '': running time = 9624841500 ns
---------------------------------------------
ns         %     Task name
---------------------------------------------
1202450400  012%  createRandoms
8422391100  088%  write

I want StopWatch to provide setTimeUnit(java.util.concurrent.TimeUnit), getLastTime(TimeUnit) and getTotalTime(TimeUnit); the return type of these methods is double.

For example,

StopWatch stopWatch = new StopWatch();
stopWatch.setTimeUnit(TimeUnit.MINUTES); // If not set, StopWatch is applied default TimeUnit.
stopWatch.start();

/* working... */

stopWatch.stop();
getTotalTime(TimeUnit.SECONDS); // 9.6248415
getTotalTime(); // 0.160414025 / Without param, it depends on StopWatch#timeUnit
System.out.println(stopWatch.prettyPrint());

is like ...

StopWatch '': running time = 0.160414025 min
---------------------------------------------
min         %     Task name
---------------------------------------------
0.02004084   012%  createRandoms
0.140373185  088%  write

Thanks!

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions