/**
   * Times the other servlet execution looping the given number of times and returns the elapsed
   * time.
   *
   * @param count the number of times to loop.
   * @return the elapsed time, in nanoseconds.
   */
  private long timeOtherServlet(final int count) throws Exception {
    final SimpleServlet servlet = new SimpleServlet();
    servlet.init(new MockServletConfig());
    final MockHttpSession simpleServletSession = new MockHttpSession();

    // JIT warm-up
    for (int i = 0; i < count; i++) {
      sendOtherServletRequest(servlet, simpleServletSession, i);
    }

    simpleServletSession.getAttributes().clear();

    Runnable runnable =
        new Runnable() {
          public void run() {
            try {
              for (int i = 0; i < count; i++) {
                sendOtherServletRequest(servlet, simpleServletSession, i);
              }
            } catch (Exception e) {
              log.error("Failed to execute test", e);
            }
          }
        };

    return time(runnable);
  }
  /**
   * Times the WServlet execution looping the given number of times and returns the elapsed time.
   *
   * @param count the number of times to loop.
   * @return the elapsed time, in nanoseconds.
   */
  private long timeWServlet(final int count) throws Exception {
    final SimpleWServlet servlet = new SimpleWServlet();
    servlet.init(new MockServletConfig());
    final MockHttpSession simpleWServletSession = new MockHttpSession();

    // Do first request to get session token
    sendWServletRequest(servlet, simpleWServletSession, 0, null);

    // Get token
    WServletHelper helper =
        new WServletHelper(
            servlet,
            new MockHttpServletRequest(simpleWServletSession),
            new MockHttpServletResponse());
    String token = helper.getUIContext().getEnvironment().getSessionToken();

    // JIT warm-up
    for (int i = 1; i < count; i++) {
      sendWServletRequest(servlet, simpleWServletSession, i, token);
    }

    simpleWServletSession.getAttributes().clear();

    // Do first request to get session token
    sendWServletRequest(servlet, simpleWServletSession, 0, null);
    final String token2 = helper.getUIContext().getEnvironment().getSessionToken();

    Runnable runnable =
        new Runnable() {
          public void run() {
            try {
              for (int i = 1; i < count; i++) {
                sendWServletRequest(servlet, simpleWServletSession, i, token2);
              }
            } catch (Exception e) {
              log.error("Failed to execute test", e);
            }
          }
        };

    return time(runnable);
  }