当前位置: 首页>>代码示例>>C#>>正文


C# ConcurrentStack.Average方法代码示例

本文整理汇总了C#中ConcurrentStack.Average方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentStack.Average方法的具体用法?C# ConcurrentStack.Average怎么用?C# ConcurrentStack.Average使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConcurrentStack的用法示例。


在下文中一共展示了ConcurrentStack.Average方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Stopwatch decode = new Stopwatch();

            //Load jpeg into reusable byte array
            //var stream = new MemoryStream(File.ReadAllBytes("large.jpg"));
            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GdiBench.mountain-jpg.jpg");
            var ms = new MemoryStream();
            stream.CopyTo(ms);
            var bytes = ms.ToArray();

            //Create PNG version via IR
            MemoryStream pngStream = new MemoryStream();
            ImageBuilder.Current.Build(new MemoryStream(bytes), pngStream, new Instructions("format=png"));
            var pngBytes = ImageResizer.ExtensionMethods.StreamExtensions.CopyToBytes(pngStream, true);

            var endecodingBenchmarks = new List<Tuple<string, Action>>();

            //Since we're doing so many decoding tests, make a template
            Func<byte[],Func<Stream,Image>,Action> CreateDecodeTest = (byte[] inputBytes, Func<Stream, Image> decoder) => {
                return () => {
                    var bytesRead = new ConcurrentStack<long>();
                    Timing.MeasureOperation(delegate(object input, TimeSegment time)
                    {
                        var readStream = new InstrumentedMemoryStream((byte[])input);
                        time.MarkStart();
                        using (var bit = decoder(readStream))
                        {
                            time.MarkStop();
                            bytesRead.Push(readStream.BytesRead);
                            var test = bit.Width;
                        }

                    }, inputBytes);
                    Console.WriteLine("Average bytes read per thread: " + bytesRead.Average().ToString());
                };
            };

            endecodingBenchmarks.Add(new Tuple<string, Action>("Measure new Bitmap(stream,useIcm=true) (jpeg)",
                CreateDecodeTest(bytes, (s) => new Bitmap(s,true))
            ));

            endecodingBenchmarks.Add(new Tuple<string, Action>("Measure new Bitmap(stream,useIcm=true) (png)",
                CreateDecodeTest(pngBytes, (s) => new Bitmap(s, true))
            ));

            endecodingBenchmarks.Add(new Tuple<string, Action>("Measure Bitmap.FromStream(readStream,true,true) (jpeg)",
                CreateDecodeTest(bytes, (s) => Bitmap.FromStream(s, true, true))
            ));

            endecodingBenchmarks.Add(new Tuple<string, Action>("Measure Bitmap.Save (jpeg)",
               () => {
                   Timing.MeasureOperation(delegate(object input, TimeSegment time)
                   {
                       var readStream = new MemoryStream((byte[])input);
                       using (var bit = System.Drawing.Bitmap.FromStream(readStream, false, true))
                       using (EncoderParameters p = new EncoderParameters(1))
                       using (var ep = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)90))
                       {
                           var outStream = new MemoryStream(readStream.Capacity);
                           p.Param[0] = ep;
                           time.MarkStart();
                           bit.Save(outStream, GetImageCodeInfo("image/jpeg"), p);
                           time.MarkStop();
                       }
                   }, bytes);
               }
               ));

            var resizeBenchmarks = new List<Tuple<string, Action>>();
            resizeBenchmarks.Add(new Tuple<string, Action>("Measure DrawImage -> 500x500",
               () =>
               {
                   Timing.MeasureOperation(delegate(object input, TimeSegment time)
                   {
                       var readStream = new InstrumentedMemoryStream((byte[])input);
                       readStream.BytesRead = 0;

                       using (var bit = new Bitmap(readStream, true))
                       {
                           readStream.SleepMsPerReadCall = 50;
                           readStream.BytesRead = 0;

                           var dest = MathUtil.ScaleWithin(bit.Width, bit.Height, 500, 500);

                           using (var canvas = new Bitmap(dest.Item1, dest.Item2))
                           using (var g = Graphics.FromImage(canvas))
                           using (var attrs = new ImageAttributes() { })
                           {
                               attrs.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
                               g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                               g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                               g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                               g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                               g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                               time.MarkStart();

                               g.DrawImage(bit, new Point[] { new Point(0, 0), new Point(dest.Item1, 0), new Point(0, dest.Item2) },
                                   new Rectangle(0, 0, bit.Width, bit.Height), GraphicsUnit.Pixel, attrs);
//.........这里部分代码省略.........
开发者ID:BEEden,项目名称:GdiBench,代码行数:101,代码来源:Program.cs


注:本文中的ConcurrentStack.Average方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。