Skip to content

Instantly share code, notes, and snippets.

@spullara
Created February 21, 2013 21:30
Show Gist options
  • Save spullara/5008433 to your computer and use it in GitHub Desktop.
Save spullara/5008433 to your computer and use it in GitHub Desktop.
MappingJsonFactory jf = new MappingJsonFactory();
AtomicInteger lines = new AtomicInteger(0);
for (int i = 0; i < 10; i++) {
long start = System.currentTimeMillis();
Stream<String> br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(args[0])), "UTF-8")).lines();
if (i % 2 == 0) {
System.out.print("parallel: ");
br = br.parallel();
} else {
System.out.print("serial: ");
}
br.map((line) -> {
try {
return (JsonNode) jf.createParser(line).readValueAsTree();
} catch (IOException e) {
throw new RuntimeException(e);
}
}).forEach((o) -> lines.incrementAndGet());
System.out.println(lines + " " + (System.currentTimeMillis() - start));
lines.set(0);
}
}
@spullara
Copy link
Author

  int count = br.map((line) -> {
    try {
      return (JsonNode) jf.createParser(line).readValueAsTree();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }).reduce(0, (a, b) -> a + 1, Integer::sum);
  System.out.println(count + " " + (System.currentTimeMillis() - start));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment