@Test public void performanceOfTabSplit() throws Exception { StopWatch s = new StopWatch(); String line = null; final int N = 1; Pattern p = Pattern.compile("\t"); s.reset(); for (int i = 0; i < N; i++) { BufferedReader br = new BufferedReader( new InputStreamReader( FileResource.find(SilkWalkerTest.class, "scaffold1.silk").openStream())); while ((line = br.readLine()) != null) { String[] tab = p.split(line); } } _logger.info("default tab split:" + s.getElapsedTime()); s.reset(); for (int i = 0; i < N; i++) { BufferedReader br = new BufferedReader( new InputStreamReader( FileResource.find(SilkWalkerTest.class, "scaffold1.silk").openStream())); while ((line = br.readLine()) != null) { ArrayList<String> tokens = StringUtil.splitAtTab(line); } } _logger.info("my tab split:" + s.getElapsedTime()); s.reset(); for (int i = 0; i < N; i++) { BufferedReader br = new BufferedReader( new InputStreamReader( FileResource.find(SilkWalkerTest.class, "scaffold1.silk").openStream())); while ((line = br.readLine()) != null) { StringTokenizer t = new StringTokenizer(line, "\t"); ArrayList<String> tokens = new ArrayList<String>(); while (t.hasMoreTokens()) { tokens.add(t.nextToken()); } } } _logger.info("tokenizer tab split:" + s.getElapsedTime()); s.reset(); for (int i = 0; i < N; i++) { FastBufferedReader fb = new FastBufferedReader( new InputStreamReader( FileResource.find(SilkWalkerTest.class, "scaffold1.silk").openStream())); while ((line = fb.readLine()) != null) { ArrayList<String> tab = StringUtil.splitAtTab(line); } } _logger.info("fast reader:" + s.getElapsedTime()); }
@Test public void perfTest() throws Exception { StopWatch s = new StopWatch(); File in = FileResource.copyToTemp(SilkWalkerTest.class, "scaffold1.silk", new File("target")); final int N = 2; { s.reset(); int lineCount = 0; char[] buf = new char[8192]; for (int i = 0; i < N; i++) { BufferedReader fb = new BufferedReader(new FileReader(in)); for (int readSize = 0; (readSize = fb.read(buf)) != -1; ) { for (int c = 0; c < readSize; c++) { if (buf[c] == '\r') { lineCount++; if (c + 1 < readSize && buf[c + 1] == '\n') { c++; } } else if (buf[c] == '\n') { lineCount++; } } } } _logger.info(String.format("BufferedReader: %.2f", s.getElapsedTime())); } { s.reset(); int lineCount = 0; for (int i = 0; i < N; i++) { BufferedScanner fb = new BufferedScanner(new FileInputStream(in)); for (CharSequence line; (line = fb.nextLine()) != null; lineCount++) {} } _logger.info( String.format("BufferedScanner nextLine: %.2f, line:%d", s.getElapsedTime(), lineCount)); } { s.reset(); int lineCount = 0; for (int i = 0; i < N; i++) { BufferedReader fb = new BufferedReader(new FileReader(in)); for (String line; (line = fb.readLine()) != null; lineCount++) {} } _logger.info( String.format("BufferedReader readLine: %.2f, line:%d", s.getElapsedTime(), lineCount)); } { s.reset(); int lineCount = 0; for (int i = 0; i < N; i++) { BufferedScanner fb = new BufferedScanner(new FileInputStream(in)); for (CharSequence line; (line = fb.nextLine()) != null; lineCount++) { String st = line.toString(); } } _logger.info( String.format( "BufferedScanner nextLine (with String conversion): %.2f, line:%d", s.getElapsedTime(), lineCount)); } { s.reset(); int lineCount = 0; for (int i = 0; i < N; i++) { BufferedScanner fb = new BufferedScanner(new FileReader(in)); for (CharSequence line; (line = fb.nextLine()) != null; lineCount++) {} } _logger.info( String.format( "BufferedScanner nextLine with Reader input: %.2f, line:%d", s.getElapsedTime(), lineCount)); } { s.reset(); int lineCount = 0; char[] buf = new char[8192]; for (int i = 0; i < N; i++) { FastBufferedReader fb = new FastBufferedReader(new FileReader(in)); for (int readSize = 0; (readSize = fb.read(buf)) != -1; ) { for (int c = 0; c < readSize; c++) { if (buf[c] == '\r') { lineCount++; if (c + 1 < readSize && buf[c + 1] == '\n') { c++; } } else if (buf[c] == '\n') { lineCount++; } } } } _logger.info(String.format("FastBufferedReader: %.2f", s.getElapsedTime())); } { s.reset(); int lineCount = 0; byte[] buf = new byte[8192]; for (int i = 0; i < N; i++) { FastBufferedInputStream fb = new FastBufferedInputStream(new FileInputStream(in)); for (int readSize = 0; (readSize = fb.read(buf)) != -1; ) { for (int c = 0; c < readSize; c++) { if (buf[c] == '\r') { lineCount++; if (c + 1 < readSize && buf[c + 1] == '\n') { c++; } } else if (buf[c] == '\n') { lineCount++; } } } } _logger.info(String.format("FastBufferedInputStream: %.2f", s.getElapsedTime())); } { s.reset(); int lineCount = 0; byte[] buf = new byte[8192]; for (int i = 0; i < N; i++) { BufferedInputStream fb = new BufferedInputStream(new FileInputStream(in)); for (int readSize = 0; (readSize = fb.read(buf)) != -1; ) { for (int c = 0; c < readSize; c++) { if (buf[c] == '\r') { lineCount++; if (c + 1 < readSize && buf[c + 1] == '\n') { c++; } } else if (buf[c] == '\n') { lineCount++; } } } } _logger.info(String.format("BufferedInputStream: %.2f", s.getElapsedTime())); } }