private static double RunVectorTriad(long vectorLength, long repetitions, int numberOfThreads)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();

            TriadData[] data = new TriadData[numberOfThreads];
            for (int i = 0; i < numberOfThreads; i++)
            {
                data[i] = new TriadData(vectorLength);
            }

            IDummy dummy = DummyFactory.Get();

            Task[] tasks = new Task[numberOfThreads];
            for (int i = 0; i < numberOfThreads; i++)
            {
                int threadIndex = i;
                tasks[i] = new Task(() => RunVectorTriad(data[threadIndex], vectorLength, repetitions, dummy));
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < numberOfThreads; i++)
            {
                tasks[i].Start();
            }
            Task.WaitAll(tasks.Take(numberOfThreads).ToArray());

            stopwatch.Stop();


            return((double)stopwatch.ElapsedMilliseconds / repetitions);
        }
示例#2
0
        public void ExportWithAttributesAndSomeSheetsNames()
        {
            IList <DummyPersonWithAttributes> dummyPeopleSheet1 = new List <DummyPersonWithAttributes>();
            IList <DummyPersonWithAttributes> dummyPeopleSheet2 = new List <DummyPersonWithAttributes>();
            IList <DummyPersonWithAttributes> dummyPeopleSheet3 = new List <DummyPersonWithAttributes>();

            for (int index = 0; index < 30; index++)
            {
                dummyPeopleSheet1.Add(DummyFactory.CreateDummyPersonWithAttributes());
            }

            for (int index = 0; index < 50; index++)
            {
                dummyPeopleSheet2.Add(DummyFactory.CreateDummyPersonWithAttributes());
            }

            for (int index = 0; index < 25; index++)
            {
                dummyPeopleSheet3.Add(DummyFactory.CreateDummyPersonWithAttributes());
            }

            IExcelExportEngine engine = new ExcelExportEngine();

            engine.AsExcel().SetFormat(ExcelVersion.XLS);
            engine.AsExcel().AddData(dummyPeopleSheet1, "Sheet Number 1");
            engine.AsExcel().AddData(dummyPeopleSheet2, "Another Sheet");
            engine.AsExcel().AddData(dummyPeopleSheet3, "Custom Name");
            var fileName = Guid.NewGuid().ToString() + "-with-attributes-some-sheets.xls";
            var filePath = PathConfig.BASE_PATH + fileName;

            engine.Export(filePath);
        }
示例#3
0
 public void SetUp()
 {
     performer = new DummyPerformer();
     factory   = new DummyFactory {
         Performer = performer
     };
     client = new Client(factory);
 }
示例#4
0
            public TestBotManager()
            {
                ApiClient = DummyFactory.CreateDummyApiClient();
                var botModule = new ChoiceBotMain.ChoiceBot(ApiClient);

                Manager = new BotManager(ApiClient);
                Manager.AddBot(botModule);
            }
示例#5
0
        public void CanDisposeMultipleTimesFact()
        {
            var factory = new DummyFactory();

            // Factories should not throw exception when disposed more than once
            factory.Dispose();
            factory.Dispose();
            factory.Dispose();
        }
示例#6
0
        public virtual void ObjectPostProcessor()
        {
            TestObject   kerry          = (TestObject)ObjectFactory.GetObject("kerry");
            TestObject   kathy          = (TestObject)ObjectFactory.GetObject("kathy");
            DummyFactory factory        = (DummyFactory)ObjectFactory.GetObject("&singletonFactory");
            TestObject   factoryCreated = (TestObject)ObjectFactory.GetObject("singletonFactory");

            Assert.IsTrue(kerry.PostProcessed);
            Assert.IsTrue(kathy.PostProcessed);
            Assert.IsTrue(factory.PostProcessed);
            Assert.IsTrue(factoryCreated.PostProcessed);
        }
示例#7
0
        public void CanStoreObjectByKeyTheory(string key)
        {
            using (var factory = new DummyFactory(key))
            {
                var dictionary  = new Dictionary <string, object>();
                var dummyObject = factory.GetPerRequest(dictionary);

                Assert.NotNull(dummyObject);
                Assert.True(dictionary.ContainsKey(key));
                Assert.Equal(dummyObject, dictionary[key]);
            }
        }
示例#8
0
    private void SpawnWave()
    {
        waveIndex++;
        var dummy = DummyFactory.GetDummy(waveIndex);

        int enemySpawnCount = Random.Range(waveIndex, waveIndex + DefaultValues.I.extraEnemyInWave);

        for (int k = 0; k < enemySpawnCount; k++)
        {
            enemies.Add(dummy);
        }
        beforeNextWave = DefaultValues.I.waveSpawnDelay;

        WaveStatPanel.SetPanel(waveIndex, enemySpawnCount, dummy.MaxHp, dummy.Speed, dummy.Damage, dummy.Gold);
    }
        public void CreateServiceHost_WhippedCreamServiceHostReturned()
        {
            IUnityContainer container = new UnityContainer();
            DummyFactory factory = new DummyFactory(container);

            var result = factory.CallProtectedCreateServiceHost(typeof(string), new System.Uri("http://localhost0978"));

            Assert.IsNotNull(result, "The result should not be null.");
            Assert.IsInstanceOf<WhippedCreamDataServiceHost>(result);

            Assert.AreEqual(typeof(string), result.Description.ServiceType,
                            "The type of the service is not what was passed in.");
            Assert.AreEqual(1, result.BaseAddresses.Count);
            Assert.AreEqual(new System.Uri("http://localhost0978"), result.BaseAddresses[0],
                            "The base address is not what was passed.");
        }
示例#10
0
        public void ExportWithAttributes()
        {
            IList <DummyPersonWithAttributes> dummyPeople = new List <DummyPersonWithAttributes>();

            for (int index = 0; index < 30; index++)
            {
                dummyPeople.Add(DummyFactory.CreateDummyPersonWithAttributes());
            }

            IExportEngine engine = new ExcelExportEngine();

            engine.AddData(dummyPeople);
            var fileName = Guid.NewGuid().ToString() + "-with-attributes.xlsx";
            var filePath = PathConfig.BASE_PATH + fileName;

            engine.Export(filePath);
        }
示例#11
0
        public void ExportWithPlainClassAndSheetName()
        {
            IList <DummyPerson> dummyPeople = new List <DummyPerson>();

            for (int index = 0; index < 30; index++)
            {
                dummyPeople.Add(DummyFactory.CreateDummyPerson());
            }

            IExcelExportEngine engine = new ExcelExportEngine();

            engine.AsExcel().SetFormat(ExcelVersion.XLS);
            engine.AsExcel().AddData(dummyPeople, "Dummy People");
            var fileName = Guid.NewGuid().ToString() + "-plain-class-sheets-names.xls";
            var filePath = PathConfig.BASE_PATH + fileName;

            engine.Export(filePath);
        }
示例#12
0
        public void ExportWithMixOrder()
        {
            IList <DummyPersonWithMixOrder> dummyPeople = new List <DummyPersonWithMixOrder>();

            for (int index = 0; index < 30; index++)
            {
                dummyPeople.Add(DummyFactory.CreateDummyPersonWithMixOrder());
            }

            IExportEngine engine = new ExcelExportEngine();

            engine.AsExcel().SetFormat(ExcelVersion.XLS);
            engine.AddData(dummyPeople);
            var fileName = Guid.NewGuid().ToString() + "-mix-order-class.xls";
            var filePath = PathConfig.BASE_PATH + fileName;

            engine.Export(filePath);
        }
示例#13
0
        public void ExportWithAttributesAndRuntimeRename()
        {
            IList <DummyPersonWithAttributes> dummyPeople = new List <DummyPersonWithAttributes>();

            for (int index = 0; index < 30; index++)
            {
                dummyPeople.Add(DummyFactory.CreateDummyPersonWithAttributes());
            }

            IExportEngine engine = new ExcelExportEngine();
            var           key    = engine.AddData(dummyPeople);

            engine.AddColumnsNames <DummyPersonWithAttributes>(key, x => x.Name, "this is a new name LOL!");
            var fileName = Guid.NewGuid().ToString() + "-with-runtime-rename.xlsx";
            var filePath = PathConfig.BASE_PATH + fileName;

            engine.Export(filePath);
        }
示例#14
0
        public void CanGetPerRequestTheory(IDictionary dictionary, bool shouldBeEqual)
        {
            using (var factory = new DummyFactory())
            {
                var dummyFirst = factory.GetPerRequest(dictionary);
                Assert.NotNull(dummyFirst);

                var dummySecond = factory.GetPerRequest(dictionary);
                Assert.NotNull(dummySecond);

                if (shouldBeEqual)
                {
                    Assert.Equal(dummyFirst, dummySecond);
                }
                else
                {
                    Assert.NotEqual(dummyFirst, dummySecond);
                }
            }
        }
示例#15
0
        public void ExportWithResourceHeaderAttributeWithOtherCulture()
        {
            IList <DummyPersonWithAttributesAndResource> dummyPeople = new List <DummyPersonWithAttributesAndResource>();

            for (int index = 0; index < 30; index++)
            {
                dummyPeople.Add(DummyFactory.CreateDummyPersonWithAttributesAndResource());
            }

            System.Threading.Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            IExportEngine engine = new ExcelExportEngine();

            engine.AsExcel().SetFormat(ExcelVersion.XLS);
            engine.AddData(dummyPeople);
            var fileName = Guid.NewGuid().ToString() + "-some-header-class.xls";
            var filePath = PathConfig.BASE_PATH + fileName;

            engine.Export(filePath);
        }
示例#16
0
        static void Main(string[] args)
        {
            Chart chart = new Chart("Runtime", "Associativity", "Runtime [s]", false);

            InitializationAndWarmup();

            //int cacheSize = (1 << 23) / 4; //Use to provoke cache thrashing. Value must be the L3 cache-size in integer (i.e. cache size in byte divided by sizeof(int)).
            int  cacheSize       = 2999999; //Use to avoid cache thrashing. May be larger than the L3 cache-size but should be prime.
            int  cacheLineLength = 64 / 4;
            int  numberOfThreads = 8;
            long repetitions     = 1 << 2;
            int  cnt             = 0;

            IDummy dummy = DummyFactory.Get();

            for (int associativity = 1; associativity <= 16; associativity++)
            {
                int   n   = cacheSize * associativity * numberOfThreads;
                int[] arr = new int[n];
                for (int i = 0; i < n; i++)
                    arr[i] = cnt++;

                fixed(int *a = arr)
                {
                    Arr array = new Arr()
                    {
                        a = a
                    };

                    Thread[] threads = new Thread[numberOfThreads];
                    for (int i = 0; i < numberOfThreads; i++)
                    {
                        int start     = associativity * cacheSize * i;
                        int coreIndex = i;
                        threads[i] = new Thread(
                            () => Run(array, start, cacheSize, cacheLineLength, associativity, repetitions, coreIndex, dummy));
                    }

                    Stopwatch stopwatch = Stopwatch.StartNew();

                    foreach (Thread thread in threads)
                    {
                        thread.Start();
                    }

                    for (int i = 0; i < numberOfThreads; i++)
                    {
                        threads[i].Join();
                    }

                    stopwatch.Stop();


                    string sumIndicator = totalSum == 42 ? "42" : "";

                    Console.WriteLine($"associativity={associativity} elapsed={stopwatch.Elapsed} {sumIndicator}");
                    chart.Add($"{numberOfThreads} threads", associativity, stopwatch.ElapsedMilliseconds);
                }
            }

            chart.Save(typeof(CacheThrashing));
            chart.Show();

            Console.WriteLine("Finished...");
            Console.ReadKey();
        }