ctubbsii commented on a change in pull request #155:
URL: https://github.com/apache/accumulo-testing/pull/155#discussion_r712630704



##########
File path: 
src/main/java/org/apache/accumulo/testing/performance/tests/ConditionalMutationsPT.java
##########
@@ -150,7 +150,9 @@ public static double 
conditionalMutationsTime(ConditionalWriter cw, long seq) th
 
     long t2 = System.nanoTime();
 
-    return 10000.0 / TimeUnit.NANOSECONDS.toSeconds(t2 - t1);
+    double nanosPerSec = (double) TimeUnit.SECONDS.toNanos(1);
+    // return number of conditions per second
+    return 10000.0 / ((t2 - t1) / nanosPerSec);

Review comment:
       > Alternatively, why not perform the calculation in nanos and convert 
the rate at the end?
   
   Because then you'd risk losing precision scaling down when you divide by the 
nanosecond duration only to multiply by 1E9 to scale back up to seconds. And 
also, it's much more readable to simply compute the number of seconds, and 
literally return `numEvents / seconds` to get the number of events per second, 
rather than convert `events/ns` to `events/s` by multiplying by `ns/s`.
   
   For reference, the code that works in `events/ns` first:
   
   ```java
   private static double rate(long numEvents, long startNanos, long stopNanos) {
     double eventsPerNano = numEvents / ((double) t2 - t1);
     double nanosPerSec = 1.0E9; // or (double) TimeUnit.SECONDS.toNanos(1);
     return eventsPerNano * nanosPerSec;
   }
   ```
   
   Every line that differs here from the previous suggestion is more confusing. 
My earlier suggestion was substantially more straight-forward.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to