ASF Bugzilla – Attachment 31994 Details for
Bug 56953
A improvement for "DataInputStream"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test case
TestFastDataInputStream.java (text/plain), 4.69 KB, created by
hzhang9
on 2014-09-11 05:52:11 UTC
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
hzhang9
Created:
2014-09-11 05:52:11 UTC
Size:
4.69 KB
patch
obsolete
>/* > * Licensed to the Apache Software Foundation (ASF) under one or more > * contributor license agreements. See the NOTICE file distributed with > * this work for additional information regarding copyright ownership. > * The ASF licenses this file to You 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 org.apache.tomcat.util.bcel.test; > >import java.io.File; >import java.io.IOException; >import java.io.InputStream; >import java.net.URL; > >import org.apache.tomcat.util.bcel.classfile.ClassParser; >import org.apache.tomcat.util.scan.Jar; >import org.apache.tomcat.util.scan.JarFactory; >import org.junit.Test; > >public class TestFastDataInputStream { > //counter > long sumOrig = 0; > long sumFDIS = 0; > > @Test > public void testFDIS() throws IOException{ > String str = System.getProperty("java.class.path"); > str = str.replace('\\', '/'); > String paths[] = str.split(";"); > //warm up > doWarmUp(paths); > //cost without cache > countWithFDIS(paths); > //cost with cache > countOrig(paths); > System.out.println("=====lots of jar files====="); > System.out.println("DataInputStream: " + sumOrig); > System.out.println("FastDataInputStream: " + sumFDIS); > sumOrig = 0; > sumFDIS = 0; > countFewWithFDIS(paths); > countFewOrig(paths); > System.out.println("=====few jar files====="); > System.out.println("DataInputStream: " + sumOrig); > System.out.println("FastDataInputStream: " + sumFDIS); > } > > //warm up > public void doWarmUp(String[] paths) throws IOException{ > for(String path:paths){ > File file = new File(path); > scanRecur(file, true); > scanRecur(file, false); > } > } > > //normal scan with DataInputStream > public void countOrig(String[] paths) throws IOException{ > boolean isFDIS = false; > for(String path : paths){ > File file = new File(path); > sumOrig += scanRecur(file, isFDIS); > } > } > > //normal scan with DataInputStream & few "jar" files > public void countFewOrig(String[] paths) throws IOException{ > boolean isFDIS = false; > for(String path : paths){ > if(path.endsWith(".jar")){ > File file = new File(path); > sumOrig += scanFew(file, isFDIS); > break; > } > } > } > > //use FastDataInputStream for "jar" files > public void countWithFDIS(String[] paths) throws IOException{ > boolean isFDIS = true; > for(String path : paths){ > File file = new File(path); > sumFDIS += scanRecur(file, isFDIS); > } > } > > //use FastDataInputStream & one "jar" file > public void countFewWithFDIS(String[] paths) throws IOException{ > boolean isFDIS = true; > for(String path : paths){ > if(path.endsWith(".jar")){ > File file = new File(path); > sumFDIS += scanFew(file, isFDIS); > break; > } > } > } > > //scan jars recursively, so that the number of jar is big. > //"isFDIS" indicates the parse model, > //"true" means use "FastDataInputStream", "false means use "DataInputStream". > public long scanRecur(File file, boolean isFDIS) throws IOException{ > String uri = file.toURI().toString(); > if(uri.endsWith(".jar")){ > URL jarUrl = new URL("jar:" + uri + "!/"); > long span = doProcess(jarUrl, isFDIS); > return span; > } > else if(file.isDirectory()){ > for(File var : file.listFiles()){ > scanRecur(var, isFDIS); > } > return 0; > } > else return 0; > } > > //scan few "jar" files > public long scanFew(File file, boolean isFDIS) throws IOException{ > String uri = file.toURI().toString(); > if(uri.endsWith(".jar")){ > URL jarUrl = new URL("jar:" + uri + "!/"); > long span = doProcess(jarUrl, isFDIS); > return span; > } > else return 0; > } > > //parse & count the cost > public static long doProcess(URL jarUrl, boolean isFDIS) throws IOException{ > ClassParser.isFDIS = isFDIS; > long span = 0; > Jar jar = null; > jar = JarFactory.newInstance(jarUrl); > jar.nextEntry(); > String entryName = jar.getEntryName(); > while (entryName != null) { > //Get ".class" entries > if (entryName.endsWith(".class")) { > InputStream di = jar.getEntryInputStream(); > ClassParser parser = new ClassParser(di, null); > long start = System.currentTimeMillis(); > parser.parse(); > long end = System.currentTimeMillis(); > span += (end - start); > > } > jar.nextEntry(); > entryName = jar.getEntryName(); > } > return span; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 56953
:
31993
|
31994
|
32008
|
32029
|
32030
|
32031