public void TryReadDoubleFormatSubstring() { int pos = 0; PaddedFormat actual = DoubleFormatCache.GetOrCreate("e5", ref pos); pos = 0; actual = DoubleFormatCache.GetOrCreate("#0.00#", ref pos); var sw = Stopwatch.StartNew(); var n = 1000000; for (int i = 0; i < n; i++) { pos = 0; DoubleFormatCache.GetOrCreate("#0.00#", ref pos); } sw.Stop(); Console.WriteLine($"// {DateTime.Today.ToShortDateString()}| TryReadDoubleFormat(\"e5\") {n:N0} times {sw.ElapsedMilliseconds} ms"); sw.Restart(); for (int i = 0; i < n; i++) { pos = 0; actual = DoubleFormatCache.GetOrCreate("#0.00#", ref pos); } sw.Stop(); Console.WriteLine($"// {DateTime.Today.ToShortDateString()}| TryReadDoubleFormat(\"#0.00#\") {n:N0} times {sw.ElapsedMilliseconds} ms"); }
public void TryRead(string text, int pos, string expected, int expectedPos) { PaddedFormat actual = DoubleFormatCache.GetOrCreate(text, ref pos); Assert.AreEqual(expected, actual.Format); Assert.AreEqual(expectedPos, pos); }
internal static PaddedFormat GetOrCreate(string format, ref int pos) { _ = WhiteSpaceReader.TryRead(format, ref pos, out var prePadding); if (DoubleFormatReader.TryRead(format, ref pos, out var valueFormat)) { _ = WhiteSpaceReader.TryRead(format, ref pos, out var postPadding); return(new PaddedFormat(prePadding, valueFormat, postPadding)); } return(PaddedFormat.CreateUnknown(prePadding, format)); }
public void TryReadError(string text, int pos, string expectedFormatted) { PaddedFormat actual = DoubleFormatCache.GetOrCreate(text, ref pos); Assert.AreEqual(text, actual.Format); Assert.AreEqual(0, pos); string formatted = null; try { formatted = 1.2.ToString(text); } catch { } Assert.AreEqual(expectedFormatted, formatted); }
public void TryReadError(string text, int pos, string expectedFormatted) { PaddedFormat actual = DoubleFormatCache.GetOrCreate(text, ref pos); Assert.AreEqual(text, actual.Format); Assert.AreEqual(0, pos); string formatted = null; try { formatted = 1.2.ToString(text); } //// ReSharper disable once EmptyGeneralCatchClause dunno what this does. catch { } Assert.AreEqual(expectedFormatted, formatted); }