@Test public void fullRequestSimulationIteration() { Services.getInstance().reset(); Services.getInstance().initializeDefaultFinder(); try { Services.getInstance().beginApplication(); Object value = null; long baseline = System.nanoTime(); for (int i = 0; i < ITERATIONS; i++) { Services.getInstance().beginRequest(); value = $(RequestService.class); value = $(ApplicationService.class); Services.getInstance().endRequest(); } long lap = System.nanoTime(); outputTime("Full request simulation", baseline, lap); } finally { Services.getInstance().reset(); } }
@Test public void injectServiceIteration() { Services.getInstance().reset(); Services.getInstance().initializeDefaultFinder(); try { Services.getInstance().beginApplication(); Services.getInstance().beginRequest(); Object value; long baseline = System.nanoTime(); for (int i = 0; i < ITERATIONS; i++) { value = $(InjectRoot.class); } long lap = System.nanoTime(); outputTime("Inject service (iterate)", baseline, lap); } finally { ApplicationServiceImpl.resetInstanceCount(); Services.getInstance().endRequest(); Services.getInstance().reset(); } }
@Test public void simpleIteration() { Object value = null; long baseline = System.nanoTime(); for (int i = 0; i < ITERATIONS; i++) { value = null; } long lap = System.nanoTime(); outputTime("Simple", baseline, lap); }
@Test public void threadLocalIteration() { Object value = null; ThreadLocal threadLocal = new ThreadLocal(); threadLocal.set(new Object()); long baseline = System.nanoTime(); for (int i = 0; i < ITERATIONS; i++) { value = threadLocal.get(); } long lap = System.nanoTime(); outputTime("ThreadLocal access", baseline, lap); }
@Test public void mapAccessIteration() { final String TEST = "test"; Object value = null; Map map = new HashMap(); map.put(TEST, new Object()); long baseline = System.nanoTime(); for (int i = 0; i < ITERATIONS; i++) { value = map.get(TEST); } long lap = System.nanoTime(); outputTime("Map access", baseline, lap); }
@Test public void beginEndRequestIteration() { Services.getInstance().reset(); Services.getInstance().initializeDefaultFinder(); try { Services.getInstance().beginApplication(); long baseline = System.nanoTime(); for (int i = 0; i < ITERATIONS; i++) { Services.getInstance().beginRequest(); Services.getInstance().endRequest(); } long lap = System.nanoTime(); outputTime("Begin/end request", baseline, lap); } finally { Services.getInstance().reset(); } }