title: Is using ThreadMXBean the right way to go when performance testing a database insert
body: <p>What would be the best method for comparing insertions when performance testing multiple db's?</p>
  
  <p>I'm currently using ThreadMXBean to check how long the CPU is spending on a certain method. <a href="https://stackoverflow.com/questions/755899/monitor-cpu-usage-per-thread-in-java">(source)</a></p>
  
  <pre><code>public static void main(String[] args) throws FileNotFoundException, IOException, ParseException, InterruptedException {
      conn = r.connection().hostname("localhost").port(28015).connect();
  
      r.db("test").table("users").delete();
      JSONParser parser = new JSONParser();
      Object obj = parser.parse(new FileReader("C:/Documents/SmallUsersFile.json"));
      JSONArray jsonObject = (JSONArray) obj;
  
      start();
          insertSmallFile(jsonObject);
      stop();
      System.out.println("Duration: " + getCpuTimeInMillis());
  
      conn.close();
  }
  
  public static void insertSmallFile(JSONArray jsonObject) throws FileNotFoundException, IOException, ParseException {
      r.db("test").table("users").insert(jsonObject).run(conn);
  }
  
  public static void start() {
      _startTime = getCpuTimeInMillis();
  }
  
  public static long stop() {
      long result = (getCpuTimeInMillis() - _startTime);
      _startTime = 0l;
      return result;
  }
  
  public static boolean isRunning() {
      return _startTime != 0l;
  }
  
  private static long getCpuTimeInMillis() {
      ThreadMXBean bean = ManagementFactory.getThreadMXBean();
      return bean.isCurrentThreadCpuTimeSupported() ? bean.getCurrentThreadCpuTime() / 1000000 : 0L;
  }
  </code></pre>
  
  <p>But I'm unsure if the actual insertion into the database is being measured or simply how long it took to execute the method. Does the thread wait until it gets an OK back?</p>