예제 #1
0
        Measurement DoOneEncodeMeasurement(ReedSolomon codec, BufferSet[] bufferSets)
        {
            long passesCompleted = 0;
            long bytesEncoded    = 0;
            long encodingTime    = 0;

            while (encodingTime < MEASUREMENT_DURATION)
            {
                BufferSet bufferSet = bufferSets[nextBuffer];
                nextBuffer = (nextBuffer + 1) % bufferSets.Length;
                byte[][] shards    = bufferSet.Buffers;
                DateTime startTime = DateTime.UtcNow;
                codec.EncodeParity(shards, 0, BUFFER_SIZE);
                DateTime endTime = DateTime.UtcNow;
                encodingTime    += (long)(endTime - startTime).TotalMilliseconds;
                bytesEncoded    += BUFFER_SIZE * DATA_COUNT;
                passesCompleted += 1;
            }

            double seconds   = encodingTime / 1000.0;
            double megabytes = bytesEncoded / 1000000.0;
            var    result    = new Measurement(megabytes, seconds);

            Console.WriteLine("        {0} passes, {1}", passesCompleted, result);

            return(result);
        }
예제 #2
0
        Measurement DoOneCheckMeasurement(ReedSolomon codec, BufferSet[] bufferSets, byte[] tempBuffer)
        {
            long passesCompleted = 0;
            long bytesChecked    = 0;
            long checkingTime    = 0;

            while (checkingTime < MEASUREMENT_DURATION)
            {
                BufferSet bufferSet = bufferSets[nextBuffer];
                nextBuffer = (nextBuffer + 1) % bufferSets.Length;
                byte[][] shards    = bufferSet.Buffers;
                DateTime startTime = DateTime.UtcNow;

                if (!codec.IsParityCorrect(shards, 0, BUFFER_SIZE, tempBuffer))
                {
                    throw new Exception("parity not correct");
                }

                DateTime endTime = DateTime.UtcNow;
                checkingTime    += (long)(endTime - startTime).TotalMilliseconds;
                bytesChecked    += BUFFER_SIZE * DATA_COUNT;
                passesCompleted += 1;
            }

            double seconds   = checkingTime / 1000.0;
            double megabytes = bytesChecked / 1000000.0;
            var    result    = new Measurement(megabytes, seconds);

            Console.WriteLine("        {0} passes, {1}", passesCompleted, result);

            return(result);
        }
예제 #3
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            while (count > 0)
            {
                BufferPartition currentBuffer = GetLatestBufferWithAvailableSpaceOrDefault();

                if (currentBuffer == default)
                {
                    byte[] newBytes = ArrayPool.Rent(MaxArraySize);
                    currentBuffer = new BufferPartition
                    {
                        Buffer     = newBytes,
                        DataLength = 0
                    };
                    BufferSet.Add(currentBuffer);
                }

                int copied = Math.Min(currentBuffer.Buffer.Length - currentBuffer.DataLength, count);
                Array.Copy(buffer, offset, currentBuffer.Buffer, currentBuffer.DataLength, copied);
                currentBuffer.DataLength += copied;
                count    -= copied;
                offset   += copied;
                Position += copied;
            }
        }
        private BufferPartition GetLatestBufferWithAvailableSpaceOrDefault()
        {
            var latestBuffer = BufferSet.LastOrDefault();

            if (latestBuffer == default || latestBuffer.DataLength >= latestBuffer.Buffer.Length)
            {
                return(default);
        private Measurement doOneEncodeMeasurement(ReedSolomon codec, BufferSet[] bufferSets)
        {
            long passesCompleted = 0;
            long bytesEncoded    = 0;
            long encodingTime    = 0;

            while (encodingTime < MEASUREMENT_DURATION)
            {
                BufferSet bufferSet = bufferSets[nextBuffer];
                nextBuffer = (nextBuffer + 1) % bufferSets.Length;
                byte[][] shards = bufferSet.buffers;
                Stopwatch stopwatch  =  new Stopwatch();
                stopwatch.Start();

                codec.encodeParity(shards, 0, BUFFER_SIZE);
                stopwatch.Stop();
                long stop = stopwatch.ElapsedMilliseconds;
                TimeSpan timespan  =  stopwatch.Elapsed;  
                    encodingTime += (long)timespan.TotalMilliseconds;
                bytesEncoded    += BUFFER_SIZE * DATA_COUNT;
                passesCompleted += 1;
            }

            double      seconds   = ((double)encodingTime) / 1000.0;
            double      megabytes = ((double)bytesEncoded) / 1000000.0;
            Measurement result    = new Measurement(megabytes, seconds);

            Console.WriteLine("        {0} passes, {1}", passesCompleted, result.ToString());
            return(result);
        }
 protected override void Dispose(bool disposing)
 {
     foreach (var buffer in BufferSet)
     {
         ArrayPool.Return(buffer.Buffer);
     }
     BufferSet.Clear();
 }
예제 #7
0
 public void Clear()
 {
     foreach (BufferPartition buffer in BufferSet)
     {
         ArrayPool.Return(buffer.Buffer);
     }
     BufferSet.Clear();
     Position = 0;
 }
        protected override void NewBuffer()
        {
            CurrentBufferToFill = BufferSet.GetFirstEmptyBuffer();
            if (CurrentBufferToFill == null)
            {
                throw new NullReferenceException(Cern.LocalizedResources.Instance().Exception_NoEmptyBuffer);
            }

            CurrentBufferToFill.Level  = (currentTreeHeight - 1);
            CurrentBufferToFill.Weight = (sampler.Weight);
        }
예제 #9
0
        protected override void NewBuffer()
        {
            CurrentBufferToFill = BufferSet.GetFirstEmptyBuffer();
            if (CurrentBufferToFill == null)
            {
                throw new NullReferenceException("Oops, no empty buffer.");
            }

            CurrentBufferToFill.Level  = (currentTreeHeight - 1);
            CurrentBufferToFill.Weight = (sampler.Weight);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected new DoubleBuffer[] BuffersToCollapse()
        {
            DoubleBuffer[] fullBuffers = BufferSet.GetFullOrPartialBuffers();

            SortAscendingByLevel(fullBuffers);

            // if there is only one buffer at the lowest level, then increase its level so that there are at least two at the lowest level.
            int minLevel = fullBuffers[1].Level;

            if (fullBuffers[0].Level < minLevel)
            {
                fullBuffers[0].Level = minLevel;
            }

            return(BufferSet.GetFullOrPartialBuffersWithLevel(minLevel));
        }
        private Measurement doOneCheckMeasurement(ReedSolomon codec, BufferSet[] bufferSets, byte[] tempBuffer)
        {
            long passesCompleted = 0;
            long bytesChecked    = 0;
            long checkingTime    = 0;

            while (checkingTime < MEASUREMENT_DURATION)
            {
                BufferSet bufferSet = bufferSets[nextBuffer];
                nextBuffer = (nextBuffer + 1) % bufferSets.Length;
                byte[][] shards = bufferSet.buffers;

                Stopwatch stopwatch  =  new Stopwatch();
                stopwatch.Start();

                if (!codec.isParityCorrect(shards, 0, BUFFER_SIZE, tempBuffer))
                {
                    // if the parity is not correct, it will throw off the
                    // benchmarking because it may return early.
                    throw new Exception("parity not correct");
                }

                stopwatch.Stop();  //  停止监视
                    TimeSpan timespan  =  stopwatch.Elapsed;  
                    checkingTime      += (long)timespan.TotalMilliseconds;
                bytesChecked    += BUFFER_SIZE * DATA_COUNT;
                passesCompleted += 1;
            }

            double      seconds   = ((double)checkingTime) / 1000.0;
            double      megabytes = ((double)bytesChecked) / 1000000.0;
            Measurement result    = new Measurement(megabytes, seconds);

            Console.WriteLine("        {0} passes, {1}", passesCompleted, result);
            return(result);
        }
예제 #12
0
        public Entity(Vector2 position, Vector2 size, Texture tex, Vector2 texScale, bool solid)
        {
            float x = size.X / 2.0f;
            float y = size.Y / 2.0f;

            float[] vertices =
            {
                -x, y,
                -x, -y,
                x,  y,
                x, -y
            };

            float[] texcoords =
            {
                0, 1,
                0, 0,
                1, 1,
                1, 0
            };

            byte[] indices =
            {
                0, 1, 2, 3
            };

            if (texScale != Vector2.One)
            {
                for (int i = 0; i < texcoords.Length; i += 2)
                {
                    texcoords[i]     *= texScale.X;
                    texcoords[i + 1] *= texScale.Y;
                }
            }

            VBO verts = new VBO(), texC = new VBO(), ind = new VBO();

            verts.SetData(ref vertices, BufferUsageHint.StaticDraw);
            texC.SetData(ref texcoords, BufferUsageHint.StaticDraw);
            ind.SetData(ref indices, BufferUsageHint.StaticDraw);

            buffers = new BufferSet();
            buffers.VertexBuffer   = verts;
            buffers.VertexSize     = 2;
            buffers.TexCoordBuffer = texC;
            buffers.TexCoordSize   = 2;
            buffers.IndexBuffer    = ind;
            buffers.DrawMode       = BeginMode.TriangleStrip;
            buffers.SetDrawState(DrawStates.Vertex | DrawStates.TexCoord);

            this.size     = size;
            this.position = position;
            this.tex      = tex;

            this.solid = solid;

            Name    = string.Empty;
            Visible = true;

            RebuildModelMatrix();
        }
예제 #13
0
        internal void Run()
        {
            Console.WriteLine("preparing...");
            BufferSet[] bufferSets = new BufferSet [NUMBER_OF_BUFFER_SETS];

            for (int iBufferSet = 0; iBufferSet < NUMBER_OF_BUFFER_SETS; iBufferSet++)
            {
                bufferSets[iBufferSet] = new BufferSet();
            }

            byte[] tempBuffer = new byte [BUFFER_SIZE];

            List <string> summaryLines = new List <string>();
            var           csv          = new StringBuilder();

            csv.Append("Outer,Middle,Inner,Multiply,Encode,Check\n");

            foreach (ICodingLoop codingLoop in CodingLoopBase.ALL_CODING_LOOPS)
            {
                var encodeAverage = new Measurement();

                {
                    string testName = codingLoop.GetType().Name + " encodeParity";
                    Console.WriteLine("\nTEST: " + testName);
                    var codec = new ReedSolomon(DATA_COUNT, PARITY_COUNT, codingLoop);
                    Console.WriteLine("    warm up...");
                    DoOneEncodeMeasurement(codec, bufferSets);
                    DoOneEncodeMeasurement(codec, bufferSets);
                    Console.WriteLine("    testing...");

                    for (int iMeasurement = 0; iMeasurement < 10; iMeasurement++)
                    {
                        encodeAverage.Add(DoOneEncodeMeasurement(codec, bufferSets));
                    }

                    Console.WriteLine("\nAVERAGE: {0}", encodeAverage);
                    summaryLines.Add($"    {testName,-45} {encodeAverage}");
                }

                // The encoding test should have filled all of the buffers with
                // correct parity, so we can benchmark parity checking.
                var checkAverage = new Measurement();

                {
                    string testName = codingLoop.GetType().Name + " isParityCorrect";
                    Console.WriteLine("\nTEST: " + testName);
                    var codec = new ReedSolomon(DATA_COUNT, PARITY_COUNT, codingLoop);
                    Console.WriteLine("    warm up...");
                    DoOneEncodeMeasurement(codec, bufferSets);
                    DoOneEncodeMeasurement(codec, bufferSets);
                    Console.WriteLine("    testing...");

                    for (int iMeasurement = 0; iMeasurement < 10; iMeasurement++)
                    {
                        checkAverage.Add(DoOneCheckMeasurement(codec, bufferSets, tempBuffer));
                    }

                    Console.WriteLine("\nAVERAGE: {0}", checkAverage);
                    summaryLines.Add($"    {testName,-45} {checkAverage}");
                }

                csv.Append(CodingLoopNameToCsvPrefix(codingLoop.GetType().Name));
                csv.Append(encodeAverage.GetRate());
                csv.Append(",");
                csv.Append(checkAverage.GetRate());
                csv.Append("\n");
            }

            Console.WriteLine("\n");
            Console.WriteLine(csv.ToString());

            Console.WriteLine("\nSummary:\n");

            foreach (string line in summaryLines)
            {
                Console.WriteLine(line);
            }
        }