//=========================================================== // 計測 //=========================================================== public void Execute(afh.Application.Log log) { // 前書き log.Lock(); log.WriteLine(); log.WriteLine(STR_LINE); log.WriteLine("\tBenchmark を開始します。"); log.WriteLine("\t\tMethodName: {0}::{1}", minfo.DeclaringType.FullName, minfo.Name); if (this.Description != "") { log.WriteLine("\t\tDescription: {0}", this.Description); } log.WriteLine(STR_LINE); log.Unlock(); try{ int loop = 1; double msecs = 0; for (int i = 1; loop > 0; loop <<= 2, i++) { log.WriteLine("第 {0} 回計測開始 (Loop 回数: {1} 回):", i, loop); TimeSpan ts = this.meth(loop); log.WriteLine("\t経過時間: {0} ms", msecs = ts.TotalMilliseconds); if (ts.Seconds != 0) { break; } if (msecs < 16.0) { loop <<= 6; } } double time = msecs / loop; int iunit = 0; if (time > 0) { while (time < 1) { time *= 1000; iunit++; } } log.WriteLine("一回当たり時間: {0:F2} {1}s", time, units[iunit]); }catch (System.Exception e) { log.WriteError(e, "Bench の実行中に例外が発生しました。"); } // 後書き log.Lock(); log.WriteLine(STR_LINE); log.WriteLine("\tBenchmark を終了しました。"); log.WriteLine(STR_LINE); log.Unlock(); }
public static void TestRegexMatch1(afh.Application.Log log) { using (log.Lock()){ StringRegex.RegLan reglan = new StringRegex.RegLan("こんにちは|さようなら"); log.WriteLine("Regular Expression: {0}", reglan); foreach (StringRegex.Capture c in reglan.Matches("こんにちは さようなら こんにちは こんにちは さようなら")) { log.WriteLine("Match! : {0}", c.Value); } reglan = new StringRegex.RegLan(@"(?<l>\d+)(?<o>(?:\+|\-))(?<r>\d+)"); log.WriteLine("Regular Expression: {0}", reglan); foreach (StringRegex.Capture c in reglan.Matches("3+2+4+5 1+2+3 2+3 4+7 123+321")) { int l = int.Parse(c.Groups["l"].Last); int r = int.Parse(c.Groups["r"].Last); bool o = c.Groups["o"].Last.Value == "+"; log.WriteLine("{0} を計算すると→: {1}", c, o?l + r:l - r); } log.WriteLine("== System.Text.RegularExpressions の場合 =="); Rgx::Regex rgx = new Rgx::Regex(@"(?<l>\d+)(?<o>(?:\+|\-))(?<r>\d+)"); log.WriteLine("Regular Expression: {0}", rgx.ToString()); foreach (Rgx::Match m in rgx.Matches("3+2+4+5 1+2+3 2+3 4+7 123+321")) { int l = int.Parse(m.Groups["l"].Value); int r = int.Parse(m.Groups["r"].Value); bool o = m.Groups["o"].Value == "+"; log.WriteLine("{0} を計算すると→: {1}", m.Value, o?l + r:l - r); } } }
public virtual unsafe System.Windows.Forms.Control GetControl() { afh.Application.Log l = UI.TreeNode.ShareLog; l.Clear(); l.Lock(); l.WriteLine("Binary dump of first 512 bytes:"); fixed(byte *img = &this.file.image[0]) { byte *table = img + (uint)entry.offset; byte *end = table + System.Math.Min((uint)entry.length, 512u); for (int i = 1; table < end; table++, i++) { l.AppendText(table->ToString("X2")); if (i >= 16) { i = 0; l.AppendText("\r\n"); } else { l.AppendText(" "); } } } l.Unlock(); return(UI.TreeNode.ShareTxtBox); }
public static void tst_DoubleNaN(afh.Application.Log log) { log.Lock(); log.WriteLine("NaN 同士"); log.WriteLine(double.NaN == 0); log.WriteLine(double.NaN != 0); log.WriteLine(double.NaN == double.NaN); log.WriteLine(double.NaN != double.NaN); log.WriteLine(double.NaN < 0); log.WriteLine(double.NaN >= 0); log.WriteLine(double.NaN < double.NaN); log.WriteLine(double.NaN >= double.NaN); log.WriteLine(); log.WriteLine("+∞ 同士"); log.WriteLine(double.PositiveInfinity == double.PositiveInfinity); log.WriteLine(double.PositiveInfinity != double.PositiveInfinity); log.WriteLine(double.PositiveInfinity < double.PositiveInfinity); log.WriteLine(double.PositiveInfinity >= double.PositiveInfinity); log.WriteLine(); log.WriteLine("-∞ 同士"); log.WriteLine(double.NegativeInfinity == double.NegativeInfinity); log.WriteLine(double.NegativeInfinity != double.NegativeInfinity); log.WriteLine(double.NegativeInfinity < double.NegativeInfinity); log.WriteLine(double.NegativeInfinity >= double.NegativeInfinity); log.WriteLine(); log.WriteLine("NaN > 色々"); log.WriteLine(double.NaN > 0); log.WriteLine(double.NaN > 1); log.WriteLine(double.NaN > -1); log.WriteLine(double.NaN > double.NegativeInfinity); log.WriteLine(double.NaN > double.PositiveInfinity); log.WriteLine(); log.Unlock(); const double inf = double.PositiveInfinity; const double NaN = double.NaN; log.Lock(); log.WriteLine("初等関数と NaN"); log.WriteVar("Atan2(∞,∞)", System.Math.Atan2(inf, inf)); log.WriteVar("Atan2(∞,NaN)", System.Math.Atan2(inf, NaN)); log.WriteVar("Atan2(0,0)", System.Math.Atan2(0, 0)); log.WriteVar("Sqrt(∞)", System.Math.Sqrt(inf)); log.WriteVar("Sqrt(NaN)", System.Math.Sqrt(NaN)); log.Unlock(); }
public static void type分岐3_準備(afh.Application.Log log) { afh.Collections.DictionaryP <int, System.Type> dic = null; afh.Collections.DictionaryP <int, System.Type> dic0; int minwrap = int.MaxValue; int minshift = 0; for (int shift = 0; shift <= 28; shift++) { int wrap = type分岐3_準備1(shift, out dic0); if (wrap < minwrap) { dic = dic0; minwrap = wrap; minshift = shift; } } log.Lock(); if (minshift == 0) { log.WriteLine("switch(t.Name.GetHashCode()&0xf){"); } else { log.WriteLine("switch((t.Name.GetHashCode()>>{0})&0xf){{", minshift); } log.AddIndent(); int c = 1; for (int i = 0; i <= 0xf; i++) { // case i: System.Text.StringBuilder build = new System.Text.StringBuilder(); build.AppendFormat("case {0}:", i); bool _else = false; foreach (System.Type type in dic[i]) { if (_else) { build.Append("else "); } build.AppendFormat("if(t==typeof({0})){{\r\n", afh.Types.CSharpName(type)); build.AppendFormat(" c+={0};\r\n", c++); build.Append(" }"); _else = true; } build.Append("break;"); log.WriteLine(build.ToString()); } log.RemoveIndent(); log.WriteLine("}"); log.Unlock(); //*/ }
public void Execute(afh.Application.Log log) { // 前書き log.Lock(); log.WriteLine(); log.WriteLine(STR_LINE); log.WriteLine("\tTest を開始します。"); log.WriteLine("\t\tMethodName: {0}::{1}", info.DeclaringType.FullName, info.Name); if (description != "") { log.WriteLine("\t\tDescription: {0}", this.description); } log.WriteLine(STR_LINE); log.Unlock(); bool failed = false; object ret = null; System.DateTime start = System.DateTime.Now; try { ret = this.info.Invoke(null, new object[] { log }); }catch (System.Exception e) { log.WriteError(e, "Test の実行中に例外が発生しました。"); failed = true; } System.TimeSpan ts = System.DateTime.Now - start; // 後書き log.Lock(); if (!failed && info.ReturnType != typeof(void)) { log.WriteLine(STR_LINE); log.WriteLine("戻り値 ({0}):", info.ReturnType); log.WriteLine(ret ?? "null"); } log.WriteLine(STR_LINE); log.WriteLine("\tTest を終了しました。"); log.WriteLine("\t\t経過時間: {0} ms", ts.TotalMilliseconds); log.WriteLine(STR_LINE); log.Unlock(); }
public static void testComposedType(afh.Application.Log log) { System.Action <System.Type> write = delegate(System.Type t){ testComposedType_write(t, log); }; Ref::MethodInfo minfo = typeof(UnitTest).GetMethod("testComposedType_meth", Ref::BindingFlags.Static | Ref::BindingFlags.NonPublic); Ref::ParameterInfo[] pinfos = minfo.GetParameters(); log.Lock(); write(typeof(int *)); write(pinfos[0].ParameterType); write(pinfos[1].ParameterType); write(pinfos[2].ParameterType); log.Unlock(); Ref::MethodInfo minfo2 = pinfos[2].ParameterType.GetMethod("Method", Ref::BindingFlags.Static | Ref::BindingFlags.Public); log.WriteLine(Types.GetMethodSignature(minfo)); log.WriteLine(Types.GetMethodSignature(minfo2)); }
public static void TestRegexParse1(afh.Application.Log log) { using (log.Lock()){ TestRegexMatch(log, "x", "x", true); TestRegexMatch(log, "y", "x", false); TestRegexMatch(log, "x|y|z", "y", true); TestRegexMatch(log, "xyz", "xyz", true); TestRegexMatch(log, "xyz", "x", false); TestRegexMatch(log, "xyz", "yxz", false); TestRegexMatch(log, "x(?:x|y)z", "xyz", true); TestRegexMatch(log, "x(?:x|y)z", "xxz", true); TestRegexMatch(log, "x(?:x|y)z", "xxzb", true); TestRegexMatch(log, "x(?:x|y)z", "xzz", false); TestRegexMatch(log, "(?:x|y)z*(?:x|y)", "xzzzzzzzzzzzzzy", true); TestRegexMatch(log, "(?:x|y)z*zzzz(?:x|y)", "xzzzzzzzzzzzzzy", true); TestRegexMatch(log, "(?:x|y)z+?z(?:x|y)", "xzzzzzzzzzzzzzy", true); TestRegexMatch(log, "(?:x|y)z*?z(?:x|y)", "xzzy", true); TestRegexMatch(log, "z{1,?}", "zzz", true); TestRegexMatch(log, "z{1,?}z", "zzz", true); TestRegexMatch(log, "z{1,+}", "zzz", true); TestRegexMatch(log, "z{1,+}z", "zzz", false); TestRegexMatch(log, "[a-z]", "e", true); TestRegexMatch(log, "[a-z-[b-o]]", "e", false); TestRegexMatch(log, "[a-z-[b-o]d-f]", "e", true); TestRegexMatch(log, "[a-z-[b-o]d-f-[e]]", "e", false); TestRegexMatch(log, @"x\p{xdigit}+y", "x08FFABy", true); TestRegexMatch(log, @"x\P{xdigit}+y", "x08FFABy", false); TestRegexMatch(log, @"x\p{xdigit}+y", "xBvy", false); TestRegexMatch(log, @"x\P{xdigit}+y", "xAvy", false); TestRegexMatch(log, "x:\"y", "ddx\"Hello World!\"yss", true); TestRegexMatch(log, "x:\"y", "ddx\"Hello World!\\\"yss", false); TestRegexMatch(log, "x:\"y", "ddx\"how are you\"ss", false); } }