static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage : MtUnZip {NameOfOsm.Bz2} {MtIsEnabled}"); return; } if (!File.Exists(args[0])) { Console.WriteLine("File {0} does not exist", args[0]); return; } bool mtIsEnabled = bool.Parse(args[1]); var timer = Stopwatch.StartNew(); var unzipper = new BZip2InputStream(File.OpenRead(args[0])); Stream bufferedReader = unzipper; if (mtIsEnabled) { bufferedReader = new MultiThreadBufferedReader(unzipper); } var rd = XmlReader.Create(bufferedReader); var nodeNameCounts = new List <NodeStats>(); while (rd.Read()) { if (rd.NodeType == XmlNodeType.Element) { var name = rd.Name; var stats = nodeNameCounts.FirstOrDefault(nodeStats => nodeStats.Name == name); if (stats == null) { stats = new NodeStats(name); nodeNameCounts.Add(stats); } stats.Update(rd); } } nodeNameCounts.Sort((lhs, rhs) => lhs.Name.CompareTo(rhs.Name)); foreach (var stats in nodeNameCounts) { Console.WriteLine("{0,20} : {1,10:N0}", stats.Name, stats.Count); } Console.WriteLine("Took {0:N0} [ms]", timer.ElapsedMilliseconds); Console.WriteLine("Total Processor time {0:N0} [ms]", Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds); }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage : MtUnZip {NameOfOsm.Bz2} {MtIsEnabled}"); return; } if (!File.Exists(args[0])) { Console.WriteLine("File {0} does not exist", args[0]); return; } bool mtIsEnabled = bool.Parse(args[1]); var timer = Stopwatch.StartNew(); var unzipper = new BZip2InputStream(File.OpenRead(args[0])); Stream bufferedReader = unzipper; if (mtIsEnabled) bufferedReader = new MultiThreadBufferedReader(unzipper); var rd = XmlReader.Create(bufferedReader); var nodeNameCounts = new List<NodeStats>(); while (rd.Read()) { if (rd.NodeType == XmlNodeType.Element) { var name = rd.Name; var stats = nodeNameCounts.FirstOrDefault(nodeStats => nodeStats.Name == name); if (stats == null) { stats = new NodeStats(name); nodeNameCounts.Add(stats); } stats.Update(rd); } } nodeNameCounts.Sort((lhs, rhs) => lhs.Name.CompareTo(rhs.Name)); foreach (var stats in nodeNameCounts) { Console.WriteLine("{0,20} : {1,10:N0}", stats.Name, stats.Count); } Console.WriteLine("Took {0:N0} [ms]", timer.ElapsedMilliseconds); Console.WriteLine("Total Processor time {0:N0} [ms]", Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds); }