ASF Bugzilla – Attachment 32031 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), 3.97 KB, created by
hzhang9
on 2014-09-17 08:57:22 UTC
(
hide
)
Description:
Test case
Filename:
MIME Type:
Creator:
hzhang9
Created:
2014-09-17 08:57:22 UTC
Size:
3.97 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.testfdis; > >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; > > // The patch works well in a large application, so this test case > // is recommended to run with plenty jar files (about 300) . > @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("=====Call FDIS first====="); > System.out.println("DataInputStream: " + sumOrig); > System.out.println("FastDataInputStream: " + sumFDIS); > sumOrig = 0; > sumFDIS = 0; > countOrig(paths); > countWithFDIS(paths); > System.out.println("=====reverse call sequency====="); > 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); > } > } > > //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); > } > } > > //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{ > long sum = 0; > String uri = file.toURI().toString(); > if(uri.endsWith(".jar")){ > URL jarUrl = new URL("jar:" + uri + "!/"); > sum += doProcess(jarUrl, isFDIS); > return sum; > } > else if(file.isDirectory()){ > for(File var : file.listFiles()){ > sum += scanRecur(var, isFDIS); > } > return sum; > } > else return sum; > } > > //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); > 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