This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public unsafe class DateParsingBench | |
{ | |
static byte[][] dates = | |
{ | |
Encoding.UTF8.GetBytes("2016-10-05T21:07:32.2082285+03:00"), | |
Encoding.UTF8.GetBytes("2016-10-05T21:07:32.2082285Z"), | |
Encoding.UTF8.GetBytes("2016-10-05T21:07:32.2082285"), | |
Encoding.UTF8.GetBytes("2016-10-05T21:07:32"), | |
Encoding.UTF8.GetBytes("2016-10-05T21:07:3"),// invalid | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResourceLocator | |
{ | |
private readonly Dictionary<string, string> _itemsIgnoreCase | |
= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
public ResourceLocator(IEnumerable<KeyValuePair<string, string>> data) | |
{ | |
foreach (var kvp in data) | |
{ | |
_itemsIgnoreCase[kvp.Key] = kvp.Value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResourceLocator | |
{ | |
private readonly Dictionary<string, string> _itemsIgnoreCase | |
= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
private readonly Dictionary<string, string> _items | |
= new Dictionary<string, string>(StringComparer.Ordinal); | |
public ResourceLocator(IEnumerable<KeyValuePair<string, string>> data) | |
{ | |
foreach (var kvp in data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResourceLocator | |
{ | |
private readonly Dictionary<string, string> _itemsIgnoreCase | |
= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
private Dictionary<string, string> _items | |
= new Dictionary<string, string>(StringComparer.Ordinal); | |
public ResourceLocator(IEnumerable<KeyValuePair<string, string>> data) | |
{ | |
foreach (var kvp in data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Linq; | |
namespace FileAnalyzer | |
{ | |
public class Record | |
{ | |
public DateTime Start => DateTime.Parse(_line.Split(' ')[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code | |
var summary = from line in File.ReadAllLines(args[0]) | |
let record = new Record(line) | |
group record by record.Id | |
into g | |
select new | |
{ | |
Id = g.Key, | |
Duration = TimeSpan.FromTicks(g.Sum(r => r.Duration.Ticks)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Record | |
{ | |
public DateTime Start; | |
public DateTime End; | |
public long Id; | |
public TimeSpan Duration => End - Start; | |
public Record(string line) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var summary = | |
from line in File.ReadLines(args[0]).AsParallel() | |
let record = new Record(line) | |
group record by record.Id | |
into g | |
select new | |
{ | |
Id = g.Key, | |
Duration = TimeSpan.FromTicks(g.Sum(r => r.Duration.Ticks)) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stats = new Dictionary<long, long>(); | |
foreach (var line in File.ReadLines(args[0])) | |
{ | |
var parts = line.Split(' '); | |
var duration = (DateTime.Parse(parts[1]) - DateTime.Parse(parts[0])).Ticks; | |
var id = long.Parse(parts[2]); | |
long existingDuration; | |
stats.TryGetValue(id, out existingDuration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stats = new ConcurrentDictionary<long, long>(); | |
Parallel.ForEach(File.ReadLines(args[0]), line => | |
{ | |
var parts = line.Split(' '); | |
var duration = (DateTime.Parse(parts[1]) - DateTime.Parse(parts[0])).Ticks; | |
var id = long.Parse(parts[2]); | |
stats.AddOrUpdate(id, duration, (_, existingDuration) => existingDuration + duration); | |
}); |