public static String formatTimeTakenNs(long startTimeNs, String message) {
    return message + " took " + (System.nanoTime() - startTimeNs) + " ns.";
  }
@Test
  public void formatTimeTakenNs() {
    class TestCase {
      Pattern mExpected;
      String mInputMessage;

      public TestCase(String expectedRE, String inputMessage) {
        mExpected = Pattern.compile(expectedRE);
        mInputMessage = inputMessage;
      }
    }

    List<TestCase> testCases = new ArrayList<>();
    testCases.add(new TestCase("^Task A took (.*) ns.$", "Task A"));
    testCases.add(new TestCase("^Task B took (.*) ns.$", "Task B"));

    long delta = 100000000;
    for (TestCase testCase : testCases) {
      String result =
          FormatUtils.formatTimeTakenNs(System.nanoTime() - delta, testCase.mInputMessage);
      Matcher match = testCase.mExpected.matcher(result);
      assertTrue(match.matches());
      assertTrue(delta <= Long.parseLong(match.group(1)));
      assertTrue(Long.parseLong(match.group(1)) <= 2 * delta);
    }
  }