Java tutorial
/** * Copyright (C) 2010 Mycila (mathieu.carbou@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mycila.guice.ext.injection; /** * Copyright (C) 2010 Mycila <mathieu.carbou@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import com.google.common.collect.Iterables; import java.io.File; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; /** * @author Mathieu Carbou (mathieu.carbou@gmail.com) */ public class Perf { public static void main(String[] args) throws Exception { perfTestMembers(); } private static void perfTestMembers() throws Exception { List<Class<?>> classes = new LinkedList<Class<?>>(); JarFile jarFile = new JarFile(new File("C:\\Program Files\\Java\\jdk1.7.0_15\\jre\\lib\\rt.jar")); Enumeration<JarEntry> enums = jarFile.entries(); while (enums.hasMoreElements()) { JarEntry entry = enums.nextElement(); if (entry.getName().endsWith(".class")) { if (entry.getName().startsWith("javax/swing") || entry.getName().startsWith("java/awt") || entry.getName().startsWith("java/awt")) classes.add(Class .forName(entry.getName().replace('/', '.').substring(0, entry.getName().length() - 6))); } } System.out.println("classes: " + classes.size()); // start visual VM Thread.sleep(10000); for (int i = 0; i < 100; i++) { System.out.println(Runtime.getRuntime().freeMemory()); long time = System.nanoTime(); for (Class<?> c : classes) { Iterables.size(Reflect.findAllAnnotatedMethods(c, Deprecated.class)); } long end = System.nanoTime(); System.out.println((end - time) + "ns = " + ((end - time) / 1000000) + "ms"); } } }