Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #1032607 // renderElapsedSecondsPleasantly - goes down to nanoseconds if value is very small

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (130L/1K).

1  
sS renderElapsedSecondsPleasantly(double seconds) {
2  
  if (seconds >= 1) ret formatDouble(seconds, 3) + " s";
3  
  double ms = seconds*1000;
4  
  if (ms >= 1) ret formatDouble(ms, 3) + " ms";
5  
  double us = ms*1000;
6  
  if (us >= 1) ret formatDouble(us, 3) + " µs";
7  
  double ns = us*1000;
8  
  ret formatDouble(ns, 3) + " ns";
9  
}
10  
11  
sS renderElapsedSecondsPleasantly(Duration d) {
12  
  ret d == null ?: renderElapsedSecondsPleasantly(nanosToSeconds(d.toNanos()));
13  
}

Author comment

Began life as a copy of #1013915

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032607
Snippet name: renderElapsedSecondsPleasantly - goes down to nanoseconds if value is very small
Eternal ID of this version: #1032607/6
Text MD5: b6fcf06723a5e287ed9b8d0646345688
Transpilation MD5: 1f1fb3671ff4c7baac7fe19db4561a71
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-01 19:09:39
Source code size: 459 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 251 / 327
Version history: 5 change(s)
Referenced in: [show references]