コード例 #1
0
        private async Task TestMultiple(int c, bool AssertIndividually, int?LogStatisticsEvery)
        {
            DateTime Start                     = DateTime.Now;
            List <FileStatistics> Stat         = null;
            List <double>         Milliseconds = null;
            int i;

            Simple[] Objects = new Simple[c];
            Simple   Obj2;

            for (i = 0; i < c; i++)
            {
                Objects[i] = CreateSimple(this.MaxStringLength);
                await this.file.SaveNewObject(Objects[i]);

                if (AssertIndividually)
                {
                    Console.Out.WriteLine();
                    Console.Out.WriteLine((i + 1).ToString() + " objects:");
                    Console.Out.WriteLine(new string('-', 80));

                    await AssertConsistent(this.file, this.provider, i + 1, Objects[i], true);
                }

                if (LogStatisticsEvery.HasValue && (i + 1) % LogStatisticsEvery.Value == 0)
                {
                    if (Stat == null)
                    {
                        Milliseconds = new List <double>();
                        Stat         = new List <FileStatistics>();
                    }

                    Milliseconds.Add((DateTime.Now - Start).TotalMilliseconds / LogStatisticsEvery.Value);
                    Stat.Add(await this.file.ComputeStatistics());

                    Start = DateTime.Now;
                }
            }

            for (i = 0; i < c; i++)
            {
                Obj2 = await this.file.LoadObject <Simple>(Objects[i].ObjectId);

                DBFilesObjectSerializationTests.AssertEqual(Objects[i], Obj2);
            }

            if (!AssertIndividually)
            {
                await AssertConsistent(this.file, this.provider, c, null, true);
            }

            if (Stat != null)
            {
                Variables v = new Variables()
                {
                    { "Stat", Stat.ToArray() },
                    { "ms", Milliseconds.ToArray() },
                    { "StepSize", LogStatisticsEvery.Value }
                };

                Expression Exp = new Expression("[ms,Stat.BlockSize,Stat.NrBlocks,Stat.NrBytesUsed,Stat.NrBytesUnused,Stat.NrBytesTotal," +
                                                "Stat.Usage,Stat.NrObjects,Stat.MinObjectSize,Stat.MaxObjectSize,Stat.AverageObjectSize,Stat.MinDepth,Stat.MaxDepth," +
                                                "Stat.NrBlockLoads,Stat.NrCacheLoads,Stat.NrBlockSaves,Stat.MinObjectsPerBlock,Stat.MaxObjectsPerBlock," +
                                                "Stat.AverageObjectsPerBlock,Stat.MinBytesUsedPerBlock,Stat.MaxBytesUsedPerBlock,Stat.AverageBytesUsedPerBlock]T");

                Console.Out.WriteLine("ms, BlockSize, NrBlocks, NrBytesUsed, NrBytesUnused, NrBytesTotal, " +
                                      "Usage, NrObjects, MinObjectSize, MaxObjectSize, AverageObjectSize, MinDepth, MaxDepth, " +
                                      "NrBlockLoads, NrCacheLoads, NrBlockSaves,Min(Obj/Block),Max(Obj/Block),Avg(Obj/Block)," +
                                      "Min(UsedBytes/Block),Max(UsedBytes/Block),Avg(UsedBytes/Block)");
                Console.Out.WriteLine(new string('-', 80));
                Console.Out.WriteLine(Exp.Evaluate(v).ToString());
            }
        }
コード例 #2
0
        private async Task TestMultiple(int NrObjects, int ArraySize, int BulkSize, bool AssertIndividually, int?LogStatisticsEvery)
        {
            DateTime Start = DateTime.Now;
            List <FileStatistics> Stat = null;
            List <double>         Milliseconds = null;
            int i = 0, j;

            Simple[]         Objects = new Simple[NrObjects];
            Simple[]         Block   = new Simple[ArraySize];
            Simple           Obj2;
            ObjectSerializer Serializer = this.provider.GetObjectSerializerEx(typeof(Simple));

            if (BulkSize > 1)
            {
                await this.provider.StartBulk();
            }

            while (i < NrObjects)
            {
                for (j = 0; j < ArraySize; j++)
                {
                    Block[j]     = CreateSimple(this.MaxStringLength);
                    Objects[i++] = Block[j];
                }

                if (ArraySize > 1)
                {
                    await this.file.SaveNewObjects(Block, Serializer);
                }
                else
                {
                    await this.file.SaveNewObject(Block[0]);
                }

                if (BulkSize > 1 && i % BulkSize == 0)
                {
                    await this.provider.EndBulk();

                    await this.provider.StartBulk();
                }

                if (AssertIndividually)
                {
                    Console.Out.WriteLine();
                    Console.Out.WriteLine(i.ToString() + " objects:");
                    Console.Out.WriteLine(new string('-', 80));

                    await AssertConsistent(this.file, this.provider, i, Objects[i - 1], true);
                }

                if (LogStatisticsEvery.HasValue && i % LogStatisticsEvery.Value == 0)
                {
                    if (Stat is null)
                    {
                        Milliseconds = new List <double>();
                        Stat         = new List <FileStatistics>();
                    }

                    Milliseconds.Add((DateTime.Now - Start).TotalMilliseconds / LogStatisticsEvery.Value);
                    Stat.Add((await this.file.ComputeStatistics()).Key);

                    Start = DateTime.Now;
                }
            }

            if (BulkSize > 1)
            {
                await this.provider.EndBulk();
            }

            for (i = 0; i < NrObjects; i++)
            {
                Obj2 = await this.file.LoadObject <Simple>(Objects[i].ObjectId);

                DBFilesObjectSerializationTests.AssertEqual(Objects[i], Obj2);
            }

            if (!AssertIndividually)
            {
                await AssertConsistent(this.file, this.provider, NrObjects, null, true);
            }

            if (Stat != null)
            {
                Variables v = new Variables()
                {
                    { "Stat", Stat.ToArray() },
                    { "ms", Milliseconds.ToArray() },
                    { "StepSize", LogStatisticsEvery.Value }
                };

                Expression Exp = new Expression("[ms,Stat.BlockSize,Stat.NrBlocks,Stat.NrBytesUsed,Stat.NrBytesUnused,Stat.NrBytesTotal," +
                                                "Stat.Usage,Stat.NrObjects,Stat.MinObjectSize,Stat.MaxObjectSize,Stat.AverageObjectSize,Stat.MinDepth,Stat.MaxDepth," +
                                                "Stat.NrBlockLoads,Stat.NrCacheLoads,Stat.NrBlockSaves,Stat.MinObjectsPerBlock,Stat.MaxObjectsPerBlock," +
                                                "Stat.AverageObjectsPerBlock,Stat.MinBytesUsedPerBlock,Stat.MaxBytesUsedPerBlock,Stat.AverageBytesUsedPerBlock]T");

                Console.Out.WriteLine("ms, BlockSize, NrBlocks, NrBytesUsed, NrBytesUnused, NrBytesTotal, " +
                                      "Usage, NrObjects, MinObjectSize, MaxObjectSize, AverageObjectSize, MinDepth, MaxDepth, " +
                                      "NrBlockLoads, NrCacheLoads, NrBlockSaves,Min(Obj/Block),Max(Obj/Block),Avg(Obj/Block)," +
                                      "Min(UsedBytes/Block),Max(UsedBytes/Block),Avg(UsedBytes/Block)");
                Console.Out.WriteLine(new string('-', 80));
                Console.Out.WriteLine(Exp.Evaluate(v).ToString());
            }
        }