( ) - :
line.Split(new char[] { '{', '<', '>', '}', ' ', '^', '"' },
StringSplitOptions.RemoveEmptyEntries);
():
Regex lineParse
= new Regex(@"^\{(<([^>]+)>\s*){3,4}(""([^""]+)""\^\^<([^>]+)>\s*)?\}$",
RegexOptions.Compiled);
Match m = lineParse.Match(line);
if (m.Groups[2].Captures.Count == 3)
{
Data data = new Data { C = m.Groups[2].Captures[0].Value,
S = m.Groups[2].Captures[1].Value, P = m.Groups[2].Captures[2].Value,
O = m.Groups[4].Value, T = m.Groups[5].Value };
} else {
Data data = new Data { C = m.Groups[2].Captures[0].Value,
S = m.Groups[2].Captures[1].Value, P = m.Groups[2].Captures[2].Value,
O = m.Groups[2].Captures[3].Value, T = String.Empty };
}
1M (String.Split ):
Method #1 Wall ( Diff) #2 Wall ( Diff)
------------------------------------------------------------
line.Split 3.6s (1.00x) 3.1s (1.00x)
myRegex.Match 5.1s (1.43x) 3.3s (1.10x)
itDependsRegex.Matches 6.8s (1.85x) 4.4s (1.44x)
stateMachine 8.4s (2.34x) 5.6s (1.82x)
alanM.Matches 9.1s (2.52x) 7.8s (2.56x)
yourRegex.Matches 18.3s (5.06x) 12.1s (1.82x)
, @AlanM @itdepends . , Regex.Matches , Regex.Match, , , . , @AlanM, , , (). @itdepends , . , , , ... kudos @RexM . Q6600 (# 2) Xeon (# 1).