Example #1
0
        public async Task ObjectForPrimaryKey_Sequential_MultiInstance_Via_Task()
        {
            await GeneratePerfRangesForBlock2(async (cache, size, keys) =>
            {
                var st      = new Stopwatch();
                var toFetch = Enumerable.Range(0, size)
                              .Select(_ => keys[prng.Next(0, keys.Count - 1)])
                              .ToArray();

                await Task.Run(async() =>
                {
                    st.Start();

                    foreach (var key in toFetch)
                    {
                        await Task.Run(() =>
                        {
                            using (var localRealm = RealmThread.GetInstance(cache.Config))
                            {
                                localRealm.Refresh();
                                var obj = localRealm.Find <KeyValueRecord>(key);
                                Assert.NotNull(obj);
                                Assert.Equal(key, obj.Key);
                            }
                        });
                    }

                    st.Stop();
                });

                return(st.ElapsedMilliseconds);
            });
        }
Example #2
0
        protected async Task GeneratePerfRangesForRealm(Func <Realms.Realm, int, Task <long> > block)
        {
            results = new Dictionary <int, long>();
            dbName  = default(string);

            var dirPath = default(string);

            using (Utility.WithEmptyDirectory(out dirPath))
                using (var cache = RealmThread.GetInstance(Path.Combine(dirPath, "realm.db")))
                {
                    using (var realmThread = new RealmThread(cache.Config))
                    {
                        realmThread.Invoke((obj) =>
                        {
                            obj.Write(() => { obj.RemoveAll(); });
                        });
                    }
                    dbName = "Realm";

                    foreach (var size in PerfHelper.GetPerfRanges())
                    {
                        results[size] = await block(cache, size);
                    }
                }
        }
Example #3
0
        async Task <Realms.Realm> GenerateRealmDB(string path)
        {
            path = path ?? IntegrationTestHelper.GetIntegrationTestRootDirectory();

            var giantDbSize = PerfHelper.GetPerfRanges().Last();
            var config      = new RealmConfiguration(Path.Combine(path, "realm.db"))
            {
                ObjectClasses = new Type[] { typeof(KeyValueRecord) }
            };
            var cache = RealmThread.GetInstance(config);

            var keys = cache.All <KeyValueRecord>().Count();

            if (keys == giantDbSize)
            {
                return(cache);
            }

            using (var realmThread = new RealmThread(cache.Config))
            {
                realmThread.Invoke((obj) =>
                {
                    obj.Write(() => { obj.RemoveAll(); });
                });
            }
            await GenerateRealmDB(cache, giantDbSize);

            return(cache);
        }
Example #4
0
        public async Task LinqWhereKey_Sequential_MultiInstance_Via_Task()
        {
            await GeneratePerfRangesForBlock2(async (cache, size, keys) =>
            {
                var st      = new Stopwatch();
                var toFetch = Enumerable.Range(0, size)
                              .Select(_ => keys[prng.Next(0, keys.Count - 1)])
                              .ToArray();

                await Task.Run(async() =>
                {
                    st.Start();

                    foreach (var key in toFetch)
                    {
                        await Task.Run(() =>
                        {
                            using (var localRealm = RealmThread.GetInstance(cache.Config))
                            {
                                var objs = localRealm.All <KeyValueRecord>().Where((KeyValueRecord c) => c.Key == key);
                                Assert.Equal(1, objs.Count());
                            }
                        });
                    }

                    st.Stop();
                });

                return(st.ElapsedMilliseconds);
            });
        }
Example #5
0
        public async Task ObjectForPrimaryKey_Parallel()
        {
            await GeneratePerfRangesForBlock2(async (cache, size, keys) =>
            {
                var st      = new Stopwatch();
                var toFetch = Enumerable.Range(0, size)
                              .Select(_ => keys[prng.Next(0, keys.Count - 1)])
                              .ToArray();

                st.Start();

                // The following code crashes with "Invalid IL code" on iOS(?), Android not tested...
                // Invalid IL code in Tests.Performance.RealmRead
                ///< Sequential_ObjectForPrimaryKey_Parallel > c__async22
                ///< Sequential_ObjectForPrimaryKey_Parallel > c__AnonStorey23:<> m__1(string): IL_0008: stfld     0x04000443
                //at System.Reactive.Linq.ObservableImpl.Select`2 + _[TSource, TResult].OnNext(TSource value)[0x00008] in < d0067ed104ac455987b6feb85f80156b >:0

                //var scheduler = System.Reactive.Concurrency.TaskPoolScheduler.Default;
                //await toFetch
                //	.ToObservable(scheduler)
                //	.Select(key => Observable.Defer(() => GetRecordViaPrimaryKey(cache, key)))
                //	.ToArray();

                await Task.Run(() =>
                {
                    Parallel.ForEach(
                        toFetch,
                        new ParallelOptions {
                        MaxDegreeOfParallelism = 4
                    },
                        key =>
                    {
                        using (var localRealm = RealmThread.GetInstance(cache.Config))
                        {
                            localRealm.Refresh();
                            var obj = localRealm.Find <KeyValueRecord>(key);
                            Assert.NotNull(obj);
                            Assert.Equal(key, obj.Key);
                        }
                    }
                        );
                });

                st.Stop();
                return(st.ElapsedMilliseconds);
            });
        }
        protected async Task GeneratePerfRangesForRealm(Func <Realms.Realm, int, Task <long> > block)
        {
            results = new Dictionary <int, long>();
            dbName  = default(string);
            var dirPath = default(string);

            using (Utility.WithEmptyDirectory(out dirPath))
                using (var cache = RealmThread.GetInstance(Path.Combine(dirPath, "perf.realm")))
                {
                    dbName = "Realm";

                    foreach (var size in PerfHelper.GetPerfRanges())
                    {
                        results[size] = await block(cache, size);
                    }
                }
        }