public static void CompareGdToDefault(string segment = "op") { var settings = new BenchmarkingSettings(); settings.Images = new ImageProvider(); settings.Images.AddLocalImages(imageDir, "fountain-small.jpg"); //.AddBlankImages(new Tuple<int, int, string>[] { new Tuple<int, int, string>(2200, 2200, "jpg") }); //.AddLocalImages(imageDir, "quality-original.jpg", "fountain-small.jpg"); settings.SharedInstructions = new Instructions[] { new Instructions( "width=800&scale=both") }; settings.ExcludeEncoding = false; settings.ExcludeDecoding = false; settings.ExcludeBuilding = false; settings.ExcludeIO = true; settings.ParallelRuns = 2; settings.SegmentNameFilter = segment; settings.ParallelThreads = parallelThreads; settings.SequentialRuns = 16; settings.ThrowawayRuns = 2; settings.ThrowawayThreads = parallelThreads; settings.UseBarrierAroundSegment = true; var configs = new Tuple <Config, Instructions, string>[] { new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "Default"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("GdBuilder"), new Instructions("builder=gd"), "GdBuilder") }; Compare(settings, configs.Reverse()); }
public void ReverseTwoTuple() { var expected = new Tuple<int, int>(1, 42); var t = new Tuple<int, int>(42, 1); Tuple<int, int> actual = t.Reverse(); Assert.AreEqual(expected, actual); }
public void ReverseOneTuple() { var expected = new Tuple <int>(42); var t = new Tuple <int>(42); Tuple <int> actual = t.Reverse(); Assert.AreEqual(expected, actual); }
public void TestCustomComparer() { Tuple <int, string>[] oriTuples = new Tuple <int, string>[] { Tuple.Create(1, "stasi"), Tuple.Create(2, "cheka") }; var orderByIdQuery = oriTuples.OrderBy(t => t, new ComparerWithId()); CollectionAssert.AreEqual(oriTuples, orderByIdQuery); var orderByNameQuery = oriTuples.OrderBy(t => t, new ComparerWithName()); CollectionAssert.AreEqual(oriTuples.Reverse(), orderByNameQuery); }
public static void CompareFastScalingToWic(string segment = "op") { var settings = BenchmarkingDefaults(); settings.Images.AddBlankImages( new Tuple <int, int, string>[] { new Tuple <int, int, string>(4000, 3000, "jpg"), new Tuple <int, int, string>(1600, 800, "png") }); settings.SharedInstructions = new Instructions[] { new Instructions( "width=800&scale=both"), new Instructions("width=200&scale=both") }; settings.SegmentNameFilter = segment; settings.ExclusiveTimeSignificantMs = 1; var configs = new Tuple <Config, Instructions, string>[] { new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "System.Drawing"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("ImageResizer.Plugins.FastScaling.FastScalingPlugin, ImageResizer.Plugins.FastScaling"), new Instructions("fastscale=true;&down.speed=5&f.ignorealpha=true"), "FastScaling speed prioritized"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("ImageResizer.Plugins.WicBuilder.WicBuilderPlugin, ImageResizer.Plugins.Wic"), new Instructions("builder=wic"), "WIC pipeline (speed prioritized)") }; Compare(settings, configs.Reverse()); }
public static void CompareDefaultToWic(string segment = "op") { var settings = BenchmarkingDefaults(); //settings.ParallelRuns = 0; //settings.SequentialRuns = 1; //settings.ThrowawayRuns = 0; settings.Images.AddBlankImages( new Tuple <int, int, string>[] { new Tuple <int, int, string>(1600, 800, "png") }); settings.SharedInstructions = new Instructions[] { new Instructions("width=200&scale=both") }; settings.SegmentNameFilter = segment; settings.ExclusiveTimeSignificantMs = 1; var configs = new Tuple <Config, Instructions, string>[] { new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "System.Drawing"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("ImageResizer.Plugins.WicBuilder.WicBuilderPlugin, ImageResizer.Plugins.Wic"), new Instructions("builder=wic"), "WIC pipeline (speed prioritized)") }; Compare(settings, configs.Reverse()); }
public static void CompareFastScalingToDefaultHQ(string segment = "op") { var settings = BenchmarkingDefaults(); settings.Images.AddBlankImages( new Tuple <int, int, string>[] { new Tuple <int, int, string>(4800, 2400, "jpg"), new Tuple <int, int, string>(1600, 800, "png") }); settings.SharedInstructions = new Instructions[] { new Instructions( "width=800&scale=both"), new Instructions("width=200&scale=both") }; settings.SegmentNameFilter = segment; settings.ExclusiveTimeSignificantMs = 1; //settings.ParallelThreads = 2; var configs = new Tuple <Config, Instructions, string>[] { new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "System.Drawing"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("ImageResizer.Plugins.FastScaling.FastScalingPlugin, ImageResizer.Plugins.FastScaling"), new Instructions("fastscale=true&down.filter=fastcubic"), "FastCubic"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("ImageResizer.Plugins.FastScaling.FastScalingPlugin, ImageResizer.Plugins.FastScaling"), new Instructions("fastscale=true&down.filter=robidoux"), "Robidoux"), new Tuple <Config, Instructions, string>(ConfigWithPlugins("ImageResizer.Plugins.FastScaling.FastScalingPlugin, ImageResizer.Plugins.FastScaling"), new Instructions("fastscale=true&down.filter=ginseng&down.speed=-2"), "Ginseng with no halving") }; Compare(settings, configs.Reverse()); }
Variable GetCoreProperty(string propName, ParsingScript script = null) { Variable result = Variable.EmptyInstance; if (m_propertyMap.TryGetValue(propName, out result) || m_propertyMap.TryGetValue(GetRealName(propName), out result)) { return(result); } else if (propName.Equals(Constants.OBJECT_PROPERTIES, StringComparison.OrdinalIgnoreCase)) { return(new Variable(GetProperties())); } else if (propName.Equals(Constants.OBJECT_TYPE, StringComparison.OrdinalIgnoreCase)) { return(new Variable((int)Type)); } else if (propName.Equals(Constants.SIZE, StringComparison.OrdinalIgnoreCase)) { return(new Variable(GetSize())); } else if (propName.Equals(Constants.UPPER, StringComparison.OrdinalIgnoreCase)) { return(new Variable(AsString().ToUpper())); } else if (propName.Equals(Constants.LOWER, StringComparison.OrdinalIgnoreCase)) { return(new Variable(AsString().ToLower())); } else if (propName.Equals(Constants.STRING, StringComparison.OrdinalIgnoreCase)) { return(new Variable(AsString())); } else if (propName.Equals(Constants.FIRST, StringComparison.OrdinalIgnoreCase)) { if (Tuple != null && Tuple.Count > 0) { return(Tuple[0]); } return(AsString().Length > 0 ? new Variable("" + AsString()[0]) : Variable.EmptyInstance); } else if (propName.Equals(Constants.LAST, StringComparison.OrdinalIgnoreCase)) { if (Tuple != null && Tuple.Count > 0) { return(Tuple.Last <Variable>()); } return(AsString().Length > 0 ? new Variable("" + AsString().Last <char>()) : Variable.EmptyInstance); } else if (script != null && propName.Equals(Constants.INDEX_OF, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); string search = Utils.GetSafeString(args, 0); int startFrom = Utils.GetSafeInt(args, 1, 0); string param = Utils.GetSafeString(args, 2, "no_case"); StringComparison comp = param.Equals("case", StringComparison.OrdinalIgnoreCase) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; return(new Variable(AsString().IndexOf(search, startFrom, comp))); } else if (script != null && propName.Equals(Constants.SUBSTRING, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); int startFrom = Utils.GetSafeInt(args, 0, 0); int length = Utils.GetSafeInt(args, 1, AsString().Length); length = Math.Min(length, AsString().Length - startFrom); return(new Variable(AsString().Substring(startFrom, length))); } else if (script != null && propName.Equals(Constants.REVERSE, StringComparison.OrdinalIgnoreCase)) { script.GetFunctionArgs(); if (Tuple != null) { Tuple.Reverse(); } else if (Type == VarType.STRING) { char[] charArray = AsString().ToCharArray(); Array.Reverse(charArray); String = new string(charArray); } return(this); } else if (script != null && propName.Equals(Constants.SORT, StringComparison.OrdinalIgnoreCase)) { script.GetFunctionArgs(); Sort(); return(this); } else if (script != null && propName.Equals(Constants.SPLIT, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); string sep = Utils.GetSafeString(args, 0, " "); var option = Utils.GetSafeString(args, 1); return(TokenizeFunction.Tokenize(AsString(), sep, option)); } else if (script != null && propName.Equals(Constants.JOIN, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); string sep = Utils.GetSafeString(args, 0, " "); if (Tuple == null) { return(new Variable(AsString())); } var join = string.Join(sep, Tuple); return(new Variable(join)); } else if (script != null && propName.Equals(Constants.ADD, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); Variable var = Utils.GetSafeVariable(args, 0); if (Tuple != null) { Tuple.Add(var); } else if (Type == VarType.NUMBER) { Value += var.AsDouble(); } else { String += var.AsString(); } return(var); } else if (script != null && propName.Equals(Constants.AT, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); int at = Utils.GetSafeInt(args, 0); if (Tuple != null && Tuple.Count > 0) { return(Tuple.Count > at ? Tuple[at] : Variable.EmptyInstance); } string str = AsString(); return(str.Length > at ? new Variable("" + str[at]) : Variable.EmptyInstance); } else if (script != null && propName.Equals(Constants.REPLACE, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 2, propName); string oldVal = Utils.GetSafeString(args, 0); string newVal = Utils.GetSafeString(args, 1); return(new Variable(AsString().Replace(oldVal, newVal))); } else if (propName.Equals(Constants.EMPTY_WHITE, StringComparison.OrdinalIgnoreCase)) { bool isEmpty = string.IsNullOrWhiteSpace(AsString()); return(new Variable(isEmpty)); } else if (script != null && propName.Equals(Constants.REPLACE_TRIM, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 2, propName); string currentValue = AsString(); for (int i = 0; i < args.Count; i += 2) { string oldVal = Utils.GetSafeString(args, i); string newVal = Utils.GetSafeString(args, i + 1); currentValue = currentValue.Replace(oldVal, newVal); } return(new Variable(currentValue.Trim())); } else if (script != null && propName.Equals(Constants.CONTAINS, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); string val = Utils.GetSafeString(args, 0); string param = Utils.GetSafeString(args, 1, "no_case"); StringComparison comp = param.Equals("case", StringComparison.OrdinalIgnoreCase) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; bool contains = false; if (Type == Variable.VarType.ARRAY) { string lower = val.ToLower(); contains = m_dictionary != null && m_dictionary.ContainsKey(lower); if (!contains && Tuple != null) { foreach (var item in Tuple) { if (item.AsString().Equals(val, comp)) { contains = true; break; } } } } else { contains = val != "" && AsString().IndexOf(val, comp) >= 0; } return(new Variable(contains)); } else if (script != null && propName.Equals(Constants.EQUALS, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); string val = Utils.GetSafeString(args, 0); string param = Utils.GetSafeString(args, 1, "no_case"); StringComparison comp = param.Equals("case", StringComparison.OrdinalIgnoreCase) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; return(new Variable(AsString().Equals(val, comp))); } else if (script != null && propName.Equals(Constants.STARTS_WITH, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); string val = Utils.GetSafeString(args, 0); string param = Utils.GetSafeString(args, 1, "no_case"); StringComparison comp = param.Equals("case", StringComparison.OrdinalIgnoreCase) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; return(new Variable(AsString().StartsWith(val, comp))); } else if (script != null && propName.Equals(Constants.ENDS_WITH, StringComparison.OrdinalIgnoreCase)) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, propName); string val = Utils.GetSafeString(args, 0); string param = Utils.GetSafeString(args, 1, "no_case"); StringComparison comp = param.Equals("case", StringComparison.OrdinalIgnoreCase) ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; return(new Variable(AsString().EndsWith(val, comp))); } else if (script != null && propName.Equals(Constants.TRIM, StringComparison.OrdinalIgnoreCase)) { script.GetFunctionArgs(); return(new Variable(AsString().Trim())); } else if (propName.Equals(Constants.KEYS, StringComparison.OrdinalIgnoreCase)) { List <Variable> results = GetAllKeys(); return(new Variable(results)); } return(result); }
private Tuple <Point, char[]>[][] GenererLignes() { Tuple <Point, char[]>[][] lignes = new Tuple <Point, char[]> [charsAnimation.Length * cstStaticFrames][]; //int courant; //int lNum; int sens = 0; //if (this.Source == SourceTuyau.Plafond) //{ // sens = charsAnimation.Length - 1; //} for (int i = 0; i < lignes.GetLength(0); i += cstStaticFrames) { lignes[i] = new Tuple <Point, char[]> [this.Hauteur]; for (int j = 0; j < this.Hauteur; j++) { char[] ligne = new char[this.Largeur]; for (int k = 0; k < ligne.Length; k++) { ligne[k] = charsAnimation[(i / cstStaticFrames + j) % charsAnimation.Length]; //if (k+1 < ligne.Length) //{ // ligne[k + 1] = ' '; //} } lignes[i][j] = new Tuple <Point, char[]>(new Point(0, j), ligne); } for (int i2 = 1; i2 < cstStaticFrames; i2++) { lignes[i + i2] = lignes[i]; } //lignes[i] = new Tuple<Point, char[]>[this.Hauteur]; //lNum = 0; //for (; lNum < lignes[i].Length - cstHauteurBouche - 1; lNum++) //{ // courant = Math.Abs(sens - lNum); // lignes[i][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurTube) / 2, courant), ligneTube); //} //for (; lNum < lignes[i].Length - 1; lNum++) //{ // courant = Math.Abs(sens - lNum); // lignes[i][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurBouche) / 2, courant), ligneBouche); //} } //for (int i = 0; i < charsAnimation.Length; i++) //{ // List<char> animation = new List<char>(); // animation.Add(charsAnimation[i]); // while (animation.Count + 2 <= cstLargeurBouche) // { // animation.AddRange(new[] { ' ', charsAnimation[i] }); // } // courant = Math.Abs(sens - this.Hauteur + 1); // lignes[i * 2][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurBouche) / 2, courant), animation.ToArray()); // lignes[i * 2 + 1][courant] = lignes[i * 2][courant]; // lignes[(i + charsAnimation.Length) * 2][courant] = Tuple.Create(new Point((this.Largeur - cstLargeurBouche) / 2 + 1, courant), animation.ToArray()); // lignes[(i + charsAnimation.Length) * 2 + 1][courant] = lignes[(i + charsAnimation.Length) * 2][courant]; //} if (this.Source == SourceTuyau.Plafond) { return(lignes.Reverse().ToArray()); } return(lignes); }