From bd1e083cd6e1c91baecb60ffb919cfb8e806b7ec Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 19 Jan 2016 21:32:37 -0500 Subject: [PATCH] nim-perf experiment --- perf/nimcat.nim | 2 ++ perf/nimcut.nim | 15 +++++++++++++++ perf/nimlc.nim | 4 ++++ perf/nimwc.nim | 7 +++++++ 4 files changed, 28 insertions(+) create mode 100644 perf/nimcat.nim create mode 100644 perf/nimcut.nim create mode 100644 perf/nimlc.nim create mode 100644 perf/nimwc.nim diff --git a/perf/nimcat.nim b/perf/nimcat.nim new file mode 100644 index 000000000..d73ba08e6 --- /dev/null +++ b/perf/nimcat.nim @@ -0,0 +1,2 @@ +for line in stdin.lines: + echo(line) diff --git a/perf/nimcut.nim b/perf/nimcut.nim new file mode 100644 index 000000000..20349cbf2 --- /dev/null +++ b/perf/nimcut.nim @@ -0,0 +1,15 @@ +import strutils, tables + +for line in stdin.lines: + #var map: OrderedTable[string,string] + var map = {"":""}.newOrderedTable + #var map = initTable[string, string] + #var map: OrderedTable[string, string] + #var map: newOrderedTable[string, string](16) + for word in line.split(","): + var pair = word.split("=") + #echo(pair[0]) + #echo(pair[1]) + #echo() + #map[pair[0]] = pair[1] + map.add(pair[0], pair[1]) diff --git a/perf/nimlc.nim b/perf/nimlc.nim new file mode 100644 index 000000000..23fde5c7d --- /dev/null +++ b/perf/nimlc.nim @@ -0,0 +1,4 @@ +var line_count = 0 +for line in stdin.lines: + line_count += 1 +echo (line_count) diff --git a/perf/nimwc.nim b/perf/nimwc.nim new file mode 100644 index 000000000..5b796605c --- /dev/null +++ b/perf/nimwc.nim @@ -0,0 +1,7 @@ +import strutils + +var word_count = 0 +for line in stdin.lines: + for word in line.split(","): + word_count += 1 +echo (word_count)