Esempio n. 1
0
        public static TableList <T> GetTableList <T>(this IDataProvider dp, bool newConn, IDataCommand command, int capacity = 0)
        {
            TableList <T> result = null;

            dp.Read(newConn, command, x => { var tlc = new TLColumnInfo[x.FieldCount]; for (var i = 0; i < tlc.Length; i++)
                                             {
                                                 tlc[i] = new TLColumnInfo(x.GetFieldName(i), x.GetFieldType(i));
                                             }
                                             result = new TableList <T>(tlc)
                                             {
                                                 Capacity = capacity
                                             }; }
                    , x => { var v = result.Load((T)x.Get(0)); for (var i = 1; i < v.Length; i++)
                             {
                                 v[i] = x.Get(i);
                             }
                    });
            return(result);
        }
Esempio n. 2
0
        public static void Test()
        {
            int    rowCount = 1000000; //1mio
            var    now      = DateTime.Now;
            var    msg      = "Hellp from TEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
            object z;
            //on release
            TableList <long> tl = null;

            AppContext.RunBenchmark(() => {
                tl = new TableList <long>("0", "1", "2", "3", "4", "5", "6")
                {
                    Capacity = rowCount
                };                                                                             // { useIndex = true };
                for (var i = 0; i < rowCount; i++)
                {
                    //var x = tl.Add(i); x[1] = now; x[2] = msg; x[3] = int.MaxValue; x[4] = long.MaxValue; x[5] = decimal.MaxValue; x[6] = now;
                    // tl.Add(i, new object[7] { null, now, msg, int.MaxValue, long.MaxValue, decimal.MaxValue, now });
                }
                tl.AcceptChanges(true);
            }, 1, 0, "TableList:     " + rowCount);
            //first call    :total = 766 ms. mem = 144 199 484 //with index and capacity:  total = 871 ms. mem = 176 558 412
            //second call   :total = 649 ms. mem = 184 814 448
            AppContext.RunBenchmark(() => { for (var i = 0; i < rowCount; i++)
                                            {
                                                z = tl[tl.FindIndex(i)][3];
                                            }
                                    }, 1, 0, "TableListDirect(get):" + rowCount);                                                                                               //29 ms. mem = 8192
            AppContext.RunBenchmark(() => { for (var i = 0; i < rowCount; i++)
                                            {
                                                z = tl[tl.FindIndex(i)][tl.GetColumnIndex("3")];
                                            }
                                    }, 1, 0, "TableListByName(get):" + rowCount);                                                                                               //65 ms. mem = 8192
            AppContext.RunBenchmark(() => { var v = tl.Columns[3]; for (var i = 0; i < rowCount; i++)
                                            {
                                                z = tl[tl.FindIndex(i), v];
                                            }
                                    }, 1, 0, "TableListByCol(get):" + rowCount);                                                                                                   //57 ms. mem = 8192
            /*var v = new System.Data.DataTable();v.BeginLoadData(); ... v.EndLoadData();*/                                                                                        //total = 7 433 ms. mem = 446 724 640
            /*Dictionary<long, int> rowIndex = null; Dictionary<long, Dictionary<long, object>> dict = null; ... dict[rowIndex.GetValue(i, -1)][3];*/                              //2 021 ms. mem = 425 202 028 get:65 ms.

            /*List<Tuple<long, DateTime, string, int, long, decimal, DateTime>> xx = null;//tuple readonly
             * xx = new List<Tuple<long, DateTime, string, int, long, decimal, DateTime>>();...new Tuple<long, DateTime, string, int, long, decimal, DateTime>(...)*/              //218 ms. mem = 104 817 732 with index
            /*xx[rowIndex.GetValue(i, -1)].Item3;*/                                                                                                                                //30 ms. mem = 8192

            /*List<Tuple<long, DateTime, string, int, long, decimal, DateTime, Tuple<long, DateTime, string, int, long, decimal, DateTime>>> xxx = null;
             * new Tuple<long, DateTime, string, int, long, decimal, DateTime, Tuple<long, DateTime, string, int, long, decimal, DateTime>>(..., Tuple.Create((long)i, now, msg, int.MaxValue, long.MaxValue, decimal.MaxValue, now)));
             * xxx[rowIndex.GetValue(i, -1)].Rest.Item3;*/                                                                                                                         // 419 ms. mem = 140 260 856 get:34 ms.
            /*List<object[]> lo = null; ... lo.Add(new object[7] { (long)i, now, msg, int.MaxValue, long.MaxValue, decimal.MaxValue, now }); ...lo[rowIndex.GetValue(i, -1)][3] */ //636 ms. mem = 180 817 960 get:30
            Dictionary <long, int> rowIndex = null;
            List <Tuple <long?, DateTime?, string, int?, long?, decimal?, DateTime?> > xx = null;

            AppContext.RunBenchmark(() => {
                xx = new List <Tuple <long?, DateTime?, string, int?, long?, decimal?, DateTime?> >();
                for (var i = 0; i < rowCount; i++)
                {
                    xx.Add(new Tuple <long?, DateTime?, string, int?, long?, decimal?, DateTime?>(i, now, msg, int.MaxValue, long.MaxValue, decimal.MaxValue, now));
                }
                rowIndex = new Dictionary <long, int>(rowCount); for (var i = 0; i < rowCount; i++)
                {
                    rowIndex.Add(xx[i].Item1.Value, i);
                }
            }, 1, 0, "List<Tuple?>:     " + rowCount);//total = 262 ms. mem = 136 820 548 !!!!!! для List<T>, где T class с полями как в tuple и инициализация через newT(){x1=i,...} -результат тот же

            /*var t0 = new TableList<int>("v", "w", "f");
             * var r = t0.Add(1); r[1] = 111; r[2] = -1;
             * r = t0.Add(2); r[1] = 222; r[2] = -2;
             * r = t0.Add(3); r[1] = 333; r[2] = -3;
             * //t0.RebuildIndex();//индекс не нужен, количество записей не большое
             * var t1 = new TableList<int>("x", new ColumnInfo<int>("y", t0), new ColumnInfo("z"));
             * r = t1.Add(1); r[1] = 1; r[2] = 12;
             * r = t1.Add(2); r[1] = 2; r[2] = 22;
             * r = t1.Add(3); r[1] = 3; r[2] = 32;
             * //t1.RebuildIndex();////индекс не нужен, количество записей не большое
             * var t2 = new TableList<long>("a", new ColumnInfo<int>("b", t1), new ColumnInfo<long>("c", null));
             * (t2.Columns["c"] as ColumnInfo<long>).LookupTable = t2;
             * var r2 = t2.Add(1); r2[1] = 1; r2[2] = 1L;
             * for (var i = 2; i < 1000000; i++) { r2 = t2.Add(i); r2[1] = 2; r2[2] = 2L; }
             * t2.RebuildIndex();
             * t2.ColumnsExpanding = true;
             * gridView.OptionsBehavior.ReadOnly = false;
             * dataSource = t2;*/
            /*if (ot.Count < 5000) { grid.DataSource = ot; gridView.PopulateColumns(); } ;// до 5 000 отктырвает 1 сек, до 100 000 держит, но медленно
             * else {  gridView.CustomUnboundColumnData += (s, e) => { if (e.IsGetData) e.Value = ((object[])e.Row)[(int)e.Column.Tag]; };
             *      gridView.Columns.Clear();
             *      foreach (var c in ot.Columns) { var clm = gridView.Columns.AddVisible(c.Key); clm.Tag = clm.VisibleIndex = c.Value.Index; clm.UnboundType = DevExpress.Data.UnboundColumnType.String; }
             *      grid.DataSource = new DevExpress.Data.PLinq.PLinqServerModeSource() { Source = ot };// тут данные уже в строке не редактируются (видимо источник данных не поддерживает)
             * }*///для pivot PLinqServerModeSource - не применяется, но и так быстро работает (но нужно указывать правильный тип колокни f.CellFormat.FormatType = f.ValueFormat.FormatType = FormatType.Numeric;)

            Console.ReadKey();
        }