Beispiel #1
0
        private void Set(int key, bool useprev)
        {
            IPtr newptr = new PtrStub()
            {
                ptr = rnd.Next()
            };
            IPtr ptr;

            if (!control_index.TryGetValue(key, out ptr) || !useprev)
            {
                ptr = newptr;
            }
            control_index[key] = ptr;
            index.Set(key, ptr);
        }
Beispiel #2
0
        public void PerformanceTest()
        {
            int N, NThreads, NKeys;
            bool SAVETEST = true, READTEST = true;

            NKeys = 5000;

            PtrStub[] ptrs = new PtrStub[NKeys];
            for (int i = 0; i < ptrs.Length; ++i)
                ptrs[i] = new PtrStub() {ptr = i};

            using (var index = CreateNewIndex(true))
            {
                for (int i=0; i<NKeys; ++i)
                    index.Set(i, ptrs[i]);

                if (SAVETEST)
                {
                    N = 100000;
                    NThreads = 10;
                    Action<int> save = (tid) =>
                    {
                        for (int i = 0; i < N; ++i)
                        {
                            int key = rnd.Next(NKeys);
                            index.Set(key, ptrs[key]);
                        }
                    };
                    var tsave = MeasureTimeOfThredas(NThreads, save);
                    Console.WriteLine("" + (N*NThreads) + " save operations in " + NThreads + " threads elapsed: " + tsave);
                    Console.WriteLine("Save Operations in 1 sec: " + ((double) N*NThreads/tsave.TotalSeconds).ToString("### ### ###"));
                }

                if (READTEST)
                {
                    N = 100000;
                    NThreads = 10;
                    Action<int> read = (tid) =>
                    {
                        for (int i = 0; i < N; ++i)
                        {
                            int key = rnd.Next(NKeys);
                            var ptr = index.Get(key);
                        }
                    };
                    var tread = MeasureTimeOfThredas(NThreads, read);
                    Console.WriteLine("" + (N*NThreads) + " read operations in " + NThreads + " threads elapsed: " +
                                      tread);
                    Console.WriteLine("Read Operations in 1 sec: " + ((double)N * NThreads / tread.TotalSeconds).ToString("### ### ###"));
                }

                if (SAVETEST && READTEST)
                {
                    N = 100000;
                    int NReadThreads = 8, NWriteThreads = 2;
                    NThreads = NReadThreads + NWriteThreads;
                    Action<int> action = (tid) =>
                    {
                        for (int i = 0; i < N; ++i)
                        {
                            int key = rnd.Next(NKeys);
                            if (tid < NWriteThreads) index.Get(key);
                            else index.Set(key, ptrs[key]);
                        }
                    };
                    var time = MeasureTimeOfThredas(NThreads, action);
                    Console.WriteLine("" + (N * NReadThreads) + " read operations in " + NReadThreads + " threads and \n"+
                                      "" + (N*NWriteThreads) + " write operations in " +NWriteThreads +" threads elapsed: " +
                                      time);
                    Console.WriteLine("Read|Write Operations in 1 sec: " + ((double)N * NThreads / time.TotalSeconds).ToString("### ### ###"));
                }
            }
        }
Beispiel #3
0
        public void PerformanceTest()
        {
            int  N, NThreads, NKeys;
            bool SAVETEST = true, READTEST = true;

            NKeys = 5000;

            PtrStub[] ptrs = new PtrStub[NKeys];
            for (int i = 0; i < ptrs.Length; ++i)
            {
                ptrs[i] = new PtrStub()
                {
                    ptr = i
                }
            }
            ;


            using (var index = CreateNewIndex(true))
            {
                for (int i = 0; i < NKeys; ++i)
                {
                    index.Set(i, ptrs[i]);
                }


                if (SAVETEST)
                {
                    N        = 100000;
                    NThreads = 10;
                    Action <int> save = (tid) =>
                    {
                        for (int i = 0; i < N; ++i)
                        {
                            int key = rnd.Next(NKeys);
                            index.Set(key, ptrs[key]);
                        }
                    };
                    var tsave = MeasureTimeOfThredas(NThreads, save);
                    Console.WriteLine("" + (N * NThreads) + " save operations in " + NThreads + " threads elapsed: " + tsave);
                    Console.WriteLine("Save Operations in 1 sec: " + ((double)N * NThreads / tsave.TotalSeconds).ToString("### ### ###"));
                }


                if (READTEST)
                {
                    N        = 100000;
                    NThreads = 10;
                    Action <int> read = (tid) =>
                    {
                        for (int i = 0; i < N; ++i)
                        {
                            int key = rnd.Next(NKeys);
                            var ptr = index.Get(key);
                        }
                    };
                    var tread = MeasureTimeOfThredas(NThreads, read);
                    Console.WriteLine("" + (N * NThreads) + " read operations in " + NThreads + " threads elapsed: " +
                                      tread);
                    Console.WriteLine("Read Operations in 1 sec: " + ((double)N * NThreads / tread.TotalSeconds).ToString("### ### ###"));
                }

                if (SAVETEST && READTEST)
                {
                    N = 100000;
                    int NReadThreads = 8, NWriteThreads = 2;
                    NThreads = NReadThreads + NWriteThreads;
                    Action <int> action = (tid) =>
                    {
                        for (int i = 0; i < N; ++i)
                        {
                            int key = rnd.Next(NKeys);
                            if (tid < NWriteThreads)
                            {
                                index.Get(key);
                            }
                            else
                            {
                                index.Set(key, ptrs[key]);
                            }
                        }
                    };
                    var time = MeasureTimeOfThredas(NThreads, action);
                    Console.WriteLine("" + (N * NReadThreads) + " read operations in " + NReadThreads + " threads and \n" +
                                      "" + (N * NWriteThreads) + " write operations in " + NWriteThreads + " threads elapsed: " +
                                      time);
                    Console.WriteLine("Read|Write Operations in 1 sec: " + ((double)N * NThreads / time.TotalSeconds).ToString("### ### ###"));
                }
            }
        }
    }
Beispiel #4
0
 private void Set(int key, bool useprev)
 {
     IPtr newptr = new PtrStub() {ptr = rnd.Next()};
     IPtr ptr;
     if (!control_index.TryGetValue(key, out ptr) || !useprev)
         ptr = newptr;
     control_index[key] = ptr;
     index.Set(key, ptr);
 }