//--------------------------------------
package org.xerial.silk.cui;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileReader;
-import org.xerial.silk.SilkStreamReader;
+import org.xerial.silk.SilkEvent;
+import org.xerial.silk.SilkEventHandler;
+import org.xerial.silk.SilkLinePushParser;
+import org.xerial.silk.SilkParser;
import org.xerial.util.StopWatch;
import org.xerial.util.log.Logger;
import org.xerial.util.opt.Argument;
+import org.xerial.util.opt.Option;
import org.xerial.util.opt.Usage;
-import org.xerial.util.tree.TreeEvent;
+import org.xerial.util.tree.TreeEventHandlerBase;
/**
* Scan command
{
private static Logger _logger = Logger.getLogger(Scan.class);
+ public static enum ScanMode {
+ LINE, NODE, READONLY
+ }
+
@Argument(index = 0)
private String inputSilkFile = null;
+ @Option(symbol = "m", longName = "mode", description = "scan mode: line, node, readonly")
+ private ScanMode mode = ScanMode.NODE;
+
public void execute() throws Exception
{
- SilkStreamReader reader = new SilkStreamReader(new File(inputSilkFile).toURL());
- TreeEvent e;
- int count = 0;
- StopWatch timer = new StopWatch();
- while ((e = reader.next()) != null)
+ File f = new File(inputSilkFile);
+ final long fileSize = f.length();
+
+ switch (mode)
+ {
+ case NODE:
+ {
+ SilkParser parser = new SilkParser(f.toURL());
+
+ parser.parse(new TreeEventHandlerBase() {
+
+ int count = 0;
+ StopWatch timer = new StopWatch();
+
+ @Override
+ public void init() throws Exception
+ {
+ timer.reset();
+ }
+
+ @Override
+ public void visitNode(String nodeName, String immediateNodeValue) throws Exception
+ {
+ count++;
+ if (count % 1000000 == 0)
+ {
+ double time = timer.getElapsedTime();
+ double speed = count / time;
+ _logger.info(String.format("time=%5.2f, %,10.0f nodes/s", time, speed));
+ }
+
+ }
+
+ @Override
+ public void finish() throws Exception
+ {
+ double time = timer.getElapsedTime();
+ double speedPerNode = ((double) count) / time;
+ double speedInMBS = fileSize / 1024 / 1024 / time;
+ _logger.info(String
+ .format("time=%.2f, %,10.0f nodes/s, %3.2f MB/s", time, speedPerNode, speedInMBS));
+ }
+
+ });
+ break;
+ }
+ case LINE:
+ {
+ SilkLinePushParser parser = new SilkLinePushParser(f.toURL());
+ parser.parse(new SilkEventHandler() {
+
+ int lineCount = 0;
+ StopWatch timer = new StopWatch();
+
+ public void handle(SilkEvent event) throws Exception
+ {
+ lineCount++;
+ if (lineCount % 100000 == 0)
+ {
+ double time = timer.getElapsedTime();
+ double speed = lineCount / time;
+ _logger.info(String.format("time=%5.2f, line=%,10d, %,10.0f lines/s", time, lineCount, speed));
+ }
+
+ }
+ });
+
+ break;
+ }
+ case READONLY:
{
- count++;
- if (count % 1000000 == 0)
+ BufferedReader reader = new BufferedReader(new FileReader(f));
+ String line;
+
+ int lineCount = 0;
+ StopWatch timer = new StopWatch();
+
+ while ((line = reader.readLine()) != null)
{
- long line = reader.getNumReadLine();
+ lineCount++;
+ if (lineCount % 100000 == 0)
+ {
+ double time = timer.getElapsedTime();
+ double speed = lineCount / time;
+ _logger.info(String.format("time=%5.2f, line=%,10d, %,10.0f lines/s", time, lineCount, speed));
+ }
- double time = timer.getElapsedTime();
- double speed = line / time;
- _logger.info(String.format("line=%d, count=%d, time=%s, %2.2f lines/sec", line, count, time, speed));
}
+ break;
+ }
}
- _logger.info(String.format("elapsed time: %.1f sec.", timer.getElapsedTime()));
+
}
public String getName()
//--------------------------------------
package org.xerial.silk;
-import java.net.URL;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.xerial.util.FileResource;
-import org.xerial.util.StopWatch;
import org.xerial.util.log.Logger;
-import org.xerial.util.tree.TreeEventHandlerBase;
public class SilkParserTest
{
{}
@Test
- public void testParse() throws Exception
- {
- final StopWatch timer = new StopWatch();
-
- final SilkParser parser = new SilkParser(FileResource.open(SilkParserTest.class, "example.silk"));
- parser.parse(new TreeEventHandlerBase() {
-
- long count = 0;
-
- public void visitNode(String nodeName, String immediateNodeValue) throws Exception
- {
- count++;
- if (count % 100000 == 0)
- {
- double t = timer.getElapsedTime();
- long lines = parser.getNumReadLine();
- _logger.info(String.format("node count=%d, time = %.2f sec. %.0f lines/sec", count, t, lines / t));
- }
- }
- });
- }
-
- @Test
- public void testPerformance() throws Exception
- {
- //String largeFile = "file:///c:/Users/leo/work/t2k/hdrr_hni_allaxt_revised.silk";
- String largeFile = "file:///f:/cygwin/home/leo/work/t2k/hdrr_hni_allaxt_revised.silk";
-
- final SilkParser parser = new SilkParser(new URL(largeFile));
- parser.parse(new TreeEventHandlerBase() {
-
- long count = 0;
- StopWatch timer = new StopWatch();
-
- @Override
- public void init() throws Exception
- {
- timer.reset();
- }
-
- public void visitNode(String nodeName, String immediateNodeValue) throws Exception
- {
- count++;
- if (count % 100000 == 0)
- {
- double t = timer.getElapsedTime();
- long lines = parser.getNumReadLine();
- _logger.info(String.format("node count=%d, time = %.2f sec. %.0f lines/sec", count, t, lines / t));
- }
- }
- });
-
- // 8700 lines/sec (Recursive Parser on Xeon 3.0GHz dual)
-
- }
+ public void dummy()
+ {}
}