@@ -0,0 +1,2558 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.tika;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.InputStream;%0A%0Aimport org.apache.tika.io.IOUtils;%0A%0Apublic class TypeDetectionBenchmark %7B%0A%0A    private static final Tika tika = new Tika();%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        long start = System.currentTimeMillis();%0A        if (args.length %3E 0) %7B%0A            for (String arg : args) %7B%0A                benchmark(new File(arg));%0A            %7D%0A        %7D else %7B%0A            benchmark(new File(%0A                    %22../tika-parsers/src/test/resources/test-documents%22));%0A        %7D%0A        System.out.println(%0A                %22Total benchmark time: %22%0A                + (System.currentTimeMillis() - start) + %22ms%22);%0A    %7D%0A%0A    private static void benchmark(File file) throws Exception %7B%0A        if (file.isHidden()) %7B%0A            // ignore%0A        %7D else if (file.isFile()) %7B%0A            InputStream input = new FileInputStream(file);%0A            try %7B%0A                byte%5B%5D content = IOUtils.toByteArray(input);%0A                String type =%0A                    tika.detect(new ByteArrayInputStream(content));%0A                long start = System.currentTimeMillis();%0A                for (int i = 0; i %3C 1000; i++) %7B%0A                    tika.detect(new ByteArrayInputStream(content));%0A                %7D%0A                System.out.printf(%0A                        %22%256dns per Tika.detect(%25s) = %25s%25n%22,%0A                        System.currentTimeMillis() - start, file, type);%0A            %7D finally %7B%0A                input.close();%0A            %7D%0A        %7D else if (file.isDirectory()) %7B%0A            for (File child : file.listFiles()) %7B%0A                benchmark(child);%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

Optimize type detection speed