Пример #1
0
        public void BenchmarkTest()
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();
            int n = 100000;

            NTStopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                string key = Guid.NewGuid().ToString();
                if (!dic.ContainsKey(key))
                {
                    dic.Add(key, key);
                }
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);

            dic = new Dictionary <string, string>();
            NTStopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                string key = Guid.NewGuid().ToString();
                dic[key] = key;
            }
            elapsedMilliseconds = NTStopwatch.Stop();
            Console.WriteLine(elapsedMilliseconds);
            // 没啥区别
        }
Пример #2
0
        public void BenchmarkTest()
        {
            // typeof非常快,无性能问题
            int n = 10000;

            NTStopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                new List <Type> {
                    typeof(byte),
                    typeof(short),
                    typeof(bool),
                    typeof(int),
                    typeof(long),
                    typeof(Guid),
                    typeof(DateTime),
                    typeof(Decimal),
                    typeof(float),
                    typeof(double),
                    typeof(ushort),
                    typeof(uint)
                };
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }
Пример #3
0
        public void Sha1BenchmarkTest()
        {
            int n = 10000;
            List <WsMessage> messages = new List <WsMessage>();

            for (int i = 0; i < n; i++)
            {
                messages.Add(new WsMessage(Guid.NewGuid(), "test")
                {
                    Id        = Guid.NewGuid(),
                    Timestamp = Timestamp.GetTimestamp(),
                    Sign      = Guid.NewGuid().ToString(),
                    Data      = new Dictionary <string, object> {
                        { "AAAAAAAA", 1 },
                        { "BBBBBBBB", DateTime.Now },
                        { "CCCCCCCC", "hello world this is a test" },
                        { "DDDDDDDD", Guid.NewGuid() }
                    }
                });
            }
            string password = "******";

            NTStopwatch.Start();
            for (int i = 0; i < messages.Count; i++)
            {
                var message = messages[i];
                message.Sign = message.CalcSign(password);
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }
Пример #4
0
        public void GetCommandLineTest()
        {
            NTStopwatch.Start();
            var cmdLines = Windows.WMI.GetCommandLines("devenv.exe");

            for (int i = 0; i < 100; i++)
            {
                cmdLines = Windows.WMI.GetCommandLines("devenv");
            }
            foreach (var item in cmdLines)
            {
                Console.WriteLine(item);
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
            NTStopwatch.Start();
            for (int i = 0; i < 100; i++)
            {
                cmdLines = Windows.WMI.GetCommandLines("notexistprocess");
            }
            foreach (var item in cmdLines)
            {
                Console.WriteLine(item);
            }
            elapsedMilliseconds = NTStopwatch.Stop();
            Console.WriteLine(elapsedMilliseconds);
        }
Пример #5
0
            private CoinProfileViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                AddEventPath <CoinKernelProfilePropertyChangedEvent>("币种内核设置变更后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    if (_coinKernelProfileDicById.ContainsKey(message.CoinKernelId))
                    {
                        _coinKernelProfileDicById[message.CoinKernelId].OnPropertyChanged(message.PropertyName);
                    }
                }, location: this.GetType());
                AddEventPath <CoinProfilePropertyChangedEvent>("币种设置变更后刷新VM内存", LogEnum.DevConsole,
                                                               action: message => {
                    if (_coinProfileDicById.ContainsKey(message.CoinId))
                    {
                        _coinProfileDicById[message.CoinId].OnPropertyChanged(message.PropertyName);
                    }
                }, location: this.GetType());
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    _coinKernelProfileDicById.Clear();
                    _coinProfileDicById.Clear();
                }, location: this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #6
0
            private GroupViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                this.Add = new DelegateCommand(() => {
                    new GroupViewModel(Guid.NewGuid())
                    {
                        SortNumber = Count + 1
                    }.Edit.Execute(FormType.Add);
                });
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <GroupAddedEvent>("添加了组后调整VM内存", LogEnum.DevConsole,
                                               action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        GroupViewModel groupVm = new GroupViewModel(message.Source);
                        _dicById.Add(message.Source.GetId(), groupVm);
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                AddEventPath <GroupUpdatedEvent>("更新了组后调整VM内存", LogEnum.DevConsole,
                                                 action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out GroupViewModel vm))
                    {
                        int sortNumber = vm.SortNumber;
                        vm.Update(message.Source);
                        if (sortNumber != vm.SortNumber)
                        {
                            this.OnPropertyChanged(nameof(List));
                            OnPropertyChanged(nameof(SelectionOptions));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <GroupRemovedEvent>("删除了组后调整VM内存", LogEnum.DevConsole,
                                                 action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChangeds();
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #7
0
            private DriveSetViewModel()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                foreach (var drive in VirtualRoot.DriveSet.AsEnumerable())
                {
                    _drives.Add(new DriveViewModel(drive));
                }
                this.Apply = new DelegateCommand(() => {
                    VirtualRoot.DriveSet.SetVirtualMemory(_drives.ToDictionary(a => a.Name, a => a.VirtualMemoryMaxSizeMb));
                    OnPropertyChanged(nameof(TotalVirtualMemoryMb));
                    OnPropertyChanged(nameof(IsStateChanged));
                });
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #8
0
            private PoolProfileViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                AddEventPath <PoolProfilePropertyChangedEvent>("矿池设置变更后刷新VM内存", LogEnum.DevConsole,
                                                               action: message => {
                    if (_dicById.TryGetValue(message.PoolId, out PoolProfileViewModel vm))
                    {
                        vm.OnPropertyChanged(message.PropertyName);
                    }
                }, location: this.GetType());
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    _dicById.Clear();
                }, location: this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #9
0
            private CoinSnapshotDataViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                foreach (var coinVm in AppContext.Instance.CoinVms.AllCoins)
                {
                    _dicByCoinCode.Add(coinVm.Code, new CoinSnapshotDataViewModel(new MinerServer.CoinSnapshotData {
                        CoinCode            = coinVm.Code,
                        MainCoinMiningCount = 0,
                        MainCoinOnlineCount = 0,
                        DualCoinMiningCount = 0,
                        DualCoinOnlineCount = 0,
                        ShareDelta          = 0,
                        RejectShareDelta    = 0,
                        Speed     = 0,
                        Timestamp = DateTime.MinValue
                    }));
                }
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #10
0
        public void Test1()
        {
            Task task1 = Task.Factory.StartNew(() => {
                NTStopwatch.Start();
                System.Threading.Thread.Sleep(1000);
                var elapsedMilliseconds = NTStopwatch.Stop();
                Console.WriteLine(elapsedMilliseconds);
            });
            Task task2 = Task.Factory.StartNew(() => {
                NTStopwatch.Start();
                System.Threading.Thread.Sleep(1000);
                var elapsedMilliseconds = NTStopwatch.Stop();
                Console.WriteLine(elapsedMilliseconds);
            });
            Task task3 = Task.Factory.StartNew(() => {
                NTStopwatch.Start();
                System.Threading.Thread.Sleep(1000);
                var elapsedMilliseconds = NTStopwatch.Stop();
                Console.WriteLine("task3 1 " + elapsedMilliseconds);
                NTStopwatch.Start();
                System.Threading.Thread.Sleep(1000);
                elapsedMilliseconds = NTStopwatch.Stop();
                Console.WriteLine("task3 2 " + elapsedMilliseconds);
            });

            Task.WaitAll(task1, task2, task3);
        }
Пример #11
0
        public void BenchmarkTest()
        {
            int n = 10000;
            List <WsMessage> messages = new List <WsMessage>();

            for (int i = 0; i < n; i++)
            {
                messages.Add(new WsMessage(Guid.NewGuid(), "test")
                {
                    Id        = Guid.NewGuid(),
                    Timestamp = Timestamp.GetTimestamp(),
                    Sign      = Guid.NewGuid().ToString(),
                    Data      = new Dictionary <string, object> {
                        { "AAAAAAAA", 1 },
                        { "BBBBBBBB", DateTime.Now },
                        { "CCCCCCCC", "hello world this is a test" },
                        { "DDDDDDDD", Guid.NewGuid() }
                    }
                });
            }
            NTStopwatch.Start();
            for (int i = 0; i < messages.Count; i++)
            {
                var    message = messages[i];
                string json    = VirtualRoot.JsonSerializer.Serialize(message);
                VirtualRoot.JsonSerializer.Deserialize <WsMessage>(json);
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }
            private SysDicViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicByCode.Clear();
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                this.Add = new DelegateCommand(() => {
                    new SysDicViewModel(Guid.NewGuid()).Edit.Execute(null);
                });
                AddEventPath <SysDicAddedEvent>("添加了系统字典后调整VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        SysDicViewModel sysDicVm = new SysDicViewModel(message.Target);
                        _dicById.Add(message.Target.GetId(), sysDicVm);
                        if (!_dicByCode.ContainsKey(message.Target.Code))
                        {
                            _dicByCode.Add(message.Target.Code, sysDicVm);
                        }
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                AddEventPath <SysDicUpdatedEvent>("更新了系统字典后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    if (_dicById.ContainsKey(message.Target.GetId()))
                    {
                        SysDicViewModel entity = _dicById[message.Target.GetId()];
                        int sortNumber         = entity.SortNumber;
                        entity.Update(message.Target);
                        if (sortNumber != entity.SortNumber)
                        {
                            this.OnPropertyChanged(nameof(List));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <SysDicRemovedEvent>("删除了系统字典后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Remove(message.Target.GetId());
                    _dicByCode.Remove(message.Target.Code);
                    OnPropertyChangeds();
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private PoolViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllPools));
                }, location: this.GetType());
                AddEventPath <PoolAddedEvent>("添加矿池后刷新VM内存", LogEnum.DevConsole,
                                              action: (message) => {
                    _dicById.Add(message.Source.GetId(), new PoolViewModel(message.Source));
                    OnPropertyChanged(nameof(AllPools));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
                    {
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
                    }
                }, location: this.GetType());
                AddEventPath <PoolRemovedEvent>("删除矿池后刷新VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(AllPools));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
                    {
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
                        coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
                    }
                }, location: this.GetType());
                AddEventPath <PoolUpdatedEvent>("更新矿池后刷新VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out PoolViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private PackageViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllPackages));
                }, location: this.GetType());
                AddEventPath <PackageAddedEvent>("添加了包后调整VM内存", LogEnum.DevConsole,
                                                 action: (message) => {
                    _dicById.Add(message.Source.GetId(), new PackageViewModel(message.Source));
                    OnPropertyChanged(nameof(AllPackages));
                    foreach (var item in KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                }, location: this.GetType());
                AddEventPath <PackageRemovedEvent>("删除了包后调整VM内存", LogEnum.DevConsole,
                                                   action: message => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(AllPackages));
                    foreach (var item in KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                }, location: this.GetType());
                AddEventPath <PackageUpdatedEvent>("更新了包后调整VM内存", LogEnum.DevConsole,
                                                   action: message => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out PackageViewModel vm))
                    {
                        vm.Update(message.Source);
                        foreach (var item in KernelVms.AllKernels)
                        {
                            item.OnPropertyChanged(nameof(item.IsPackageValid));
                        }
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private WalletViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None,
                                                                     action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                AddEventPath <WalletAddedEvent>("添加了钱包后调整VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    _dicById.Add(message.Source.GetId(), new WalletViewModel(message.Source));
                    OnPropertyChanged(nameof(WalletList));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                    VirtualRoot.RaiseEvent(new WalletVmAddedEvent(message));
                }, location: this.GetType());
                AddEventPath <WalletRemovedEvent>("删除了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(WalletList));
                    if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.SelectedWallet));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                    VirtualRoot.RaiseEvent(new WalletVmRemovedEvent(message));
                }, location: this.GetType());
                AddEventPath <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out WalletViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #16
0
            private KernelOutputViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    AllPropertyChanged();
                }, location: this.GetType());
                AddEventPath <KernelOutputAddedEvent>("添加了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                                      action: message => {
                    var vm = new KernelOutputViewModel(message.Source);
                    _dicById.Add(message.Source.GetId(), vm);
                    OnPropertyChanged(nameof(AllKernelOutputVms));
                    OnPropertyChanged(nameof(PleaseSelectVms));
                }, location: this.GetType());
                AddEventPath <KernelOutputUpdatedEvent>("更新了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                                        action: message => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out KernelOutputViewModel vm))
                    {
                        if (vm != null)
                        {
                            vm.Update(message.Source);
                        }
                    }
                }, location: this.GetType());
                AddEventPath <KernelOutputRemovedEvent>("移除了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                                        action: message => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        _dicById.Remove(message.Source.GetId());
                        OnPropertyChanged(nameof(AllKernelOutputVms));
                        OnPropertyChanged(nameof(PleaseSelectVms));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #17
0
        public void AvailableFreeSpaceInfoTest()
        {
            Console.WriteLine(VirtualRoot.GetAvailableFreeSpaceInfo());
            NTStopwatch.Start();
            for (int i = 0; i < 1000; i++)
            {
                VirtualRoot.GetAvailableFreeSpaceInfo();
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }
Пример #18
0
        public void BenchmarkTest1()
        {
            NTStopwatch.Start();

            for (int i = 0; i < 500; i++)
            {
                var v = VirtualRoot.ProcessMemoryMb;
            }

            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }
Пример #19
0
            private MineWorkViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                foreach (var item in NTMinerRoot.Instance.MineWorkSet.AsEnumerable())
                {
                    _dicById.Add(item.GetId(), new MineWorkViewModel(item));
                }
                this.Add = new DelegateCommand(() => {
                    new MineWorkViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                AddEventPath <MineWorkAddedEvent>("添加作业后刷新VM内存", LogEnum.DevConsole,
                                                  action: message => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        _dicById.Add(message.Target.GetId(), new MineWorkViewModel(message.Target));
                        OnPropertyChanged(nameof(List));
                        OnPropertyChanged(nameof(MineWorkVmItems));
                        if (message.Target.GetId() == AppContext.Instance.MinerClientsWindowVm.SelectedMineWork.GetId())
                        {
                            AppContext.Instance.MinerClientsWindowVm.SelectedMineWork = MineWorkViewModel.PleaseSelect;
                        }
                    }
                }, location: this.GetType());
                AddEventPath <MineWorkUpdatedEvent>("更新作业后刷新VM内存", LogEnum.DevConsole,
                                                    action: message => {
                    _dicById[message.Target.GetId()].Update(message.Target);
                }, location: this.GetType());
                AddEventPath <MineWorkRemovedEvent>("删除作业后刷新VM内存", LogEnum.DevConsole,
                                                    action: message => {
                    _dicById.Remove(message.Target.GetId());
                    OnPropertyChanged(nameof(List));
                    OnPropertyChanged(nameof(MineWorkVmItems));
                    if (message.Target.GetId() == AppContext.Instance.MinerClientsWindowVm.SelectedMineWork.GetId())
                    {
                        AppContext.Instance.MinerClientsWindowVm.SelectedMineWork = MineWorkViewModel.PleaseSelect;
                    }
                }, location: this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private FragmentWriterViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                this.Add = new DelegateCommand(() => {
                    new FragmentWriterViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <FragmentWriterAddedEvent>("添加了命令行片段书写器后调整VM内存", LogEnum.DevConsole,
                                                        action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        FragmentWriterViewModel groupVm = new FragmentWriterViewModel(message.Source);
                        _dicById.Add(message.Source.GetId(), groupVm);
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                AddEventPath <FragmentWriterUpdatedEvent>("更新了命令行片段书写器后调整VM内存", LogEnum.DevConsole,
                                                          action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out FragmentWriterViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                AddEventPath <FragmentWriterRemovedEvent>("删除了命令行片段书写器后调整VM内存", LogEnum.DevConsole,
                                                          action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChangeds();
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #21
0
            private CoinGroupViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    _listByGroupId.Clear();
                    Init();
                }, location: this.GetType());
                AddEventPath <CoinGroupAddedEvent>("添加了币组后调整VM内存", LogEnum.DevConsole,
                                                   action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(message.Source);
                        _dicById.Add(message.Source.GetId(), coinGroupVm);
                        if (!_listByGroupId.ContainsKey(coinGroupVm.GroupId))
                        {
                            _listByGroupId.Add(coinGroupVm.GroupId, new List <CoinGroupViewModel>());
                        }
                        _listByGroupId[coinGroupVm.GroupId].Add(coinGroupVm);
                        OnGroupPropertyChanged(coinGroupVm.GroupId);
                    }
                }, location: this.GetType());
                AddEventPath <CoinGroupRemovedEvent>("删除了币组后调整VM内存", LogEnum.DevConsole,
                                                     action: (message) => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        var entity = _dicById[message.Source.GetId()];
                        _dicById.Remove(message.Source.GetId());
                        if (_listByGroupId.ContainsKey(entity.GroupId))
                        {
                            _listByGroupId[entity.GroupId].Remove(entity);
                        }
                        OnGroupPropertyChanged(entity.GroupId);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private PackageViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllPackages));
                }, location: this.GetType());
                AddEventPath <PackageAddedEvent>("添加了包后调整VM内存", LogEnum.DevConsole,
                                                 action: (message) => {
                    _dicById.Add(message.Target.GetId(), new PackageViewModel(message.Target));
                    OnPropertyChanged(nameof(AllPackages));
                    foreach (var item in AppContext.Instance.KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                }, location: this.GetType());
                AddEventPath <PackageRemovedEvent>("删除了包后调整VM内存", LogEnum.DevConsole,
                                                   action: message => {
                    _dicById.Remove(message.Target.GetId());
                    OnPropertyChanged(nameof(AllPackages));
                    foreach (var item in AppContext.Instance.KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                }, location: this.GetType());
                AddEventPath <PackageUpdatedEvent>("更新了包后调整VM内存", LogEnum.DevConsole,
                                                   action: message => {
                    var entity = _dicById[message.Target.GetId()];
                    entity.Update(message.Target);
                    foreach (var item in AppContext.Instance.KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #23
0
        public void TestMethod2()
        {
            int secondCount = 1000000;

            NTStopwatch.Start();
            A(secondCount, out int count1);
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine("A " + elapsedMilliseconds);
            NTStopwatch.Start();
            B(secondCount, out int count2);
            elapsedMilliseconds = NTStopwatch.Stop();
            Console.WriteLine("B " + elapsedMilliseconds);
            Assert.AreEqual(count1, count2);
        }
            private FileWriterViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                this.Add = new DelegateCommand(() => {
                    new FileWriterViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <FileWriterAddedEvent>("添加了文件书写器后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        FileWriterViewModel groupVm = new FileWriterViewModel(message.Target);
                        _dicById.Add(message.Target.GetId(), groupVm);
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                AddEventPath <FileWriterUpdatedEvent>("更新了文件书写器后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.ContainsKey(message.Target.GetId()))
                    {
                        FileWriterViewModel entity = _dicById[message.Target.GetId()];
                        entity.Update(message.Target);
                    }
                }, location: this.GetType());
                AddEventPath <FileWriterRemovedEvent>("删除了文件书写器后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    _dicById.Remove(message.Target.GetId());
                    OnPropertyChangeds();
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #25
0
            private NTMinerWalletViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                Init(refresh: false);
                AddEventPath <NTMinerWalletSetInitedEvent>("NTMiner钱包集初始化后", LogEnum.DevConsole,
                                                           action: message => {
                    Init(refresh: true);
                }, location: this.GetType());
                this.Add = new DelegateCommand(() => {
                    new NTMinerWalletViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                AddEventPath <NTMinerWalletAddedEvent>("添加NTMiner钱包后刷新VM内存", LogEnum.DevConsole,
                                                       action: message => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        _dicById.Add(message.Target.GetId(), new NTMinerWalletViewModel(message.Target));
                        if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coinVm))
                        {
                            coinVm.OnPropertyChanged(nameof(coinVm.NTMinerWallets));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <NTMinerWalletUpdatedEvent>("更新NTMiner钱包后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    _dicById[message.Target.GetId()].Update(message.Target);
                }, location: this.GetType());
                AddEventPath <NTMinerWalletRemovedEvent>("删除NTMiner钱包后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    _dicById.Remove(message.Target.GetId());
                    if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coinVm))
                    {
                        coinVm.OnPropertyChanged(nameof(coinVm.NTMinerWallets));
                    }
                }, location: this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private PoolKernelViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                AddEventPath <PoolKernelAddedEvent>("新添了矿池内核后刷新矿池内核VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        if (PoolVms.TryGetPoolVm(message.Source.PoolId, out PoolViewModel poolVm))
                        {
                            _dicById.Add(message.Source.GetId(), new PoolKernelViewModel(message.Source));
                            poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <PoolKernelRemovedEvent>("移除了币种内核后刷新矿池内核VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        var vm = _dicById[message.Source.GetId()];
                        _dicById.Remove(message.Source.GetId());
                        if (PoolVms.TryGetPoolVm(vm.PoolId, out PoolViewModel poolVm))
                        {
                            poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <PoolKernelUpdatedEvent>("更新了矿池内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out PoolKernelViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private UserViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                this.Add = new DelegateCommand(() => {
                    if (!VirtualRoot.IsMinerStudio)
                    {
                        return;
                    }
                    new UserViewModel().Edit.Execute(FormType.Add);
                });
                AddEventPath <UserAddedEvent>("添加了用户后", LogEnum.DevConsole,
                                              action: message => {
                    if (!_dicByLoginName.ContainsKey(message.Target.LoginName))
                    {
                        _dicByLoginName.Add(message.Target.LoginName, new UserViewModel(message.Target));
                        OnPropertyChanged(nameof(List));
                    }
                }, location: this.GetType());
                AddEventPath <UserUpdatedEvent>("更新了用户后", LogEnum.DevConsole,
                                                action: message => {
                    if (_dicByLoginName.TryGetValue(message.Target.LoginName, out UserViewModel vm))
                    {
                        vm.Update(message.Target);
                    }
                }, location: this.GetType());
                AddEventPath <UserRemovedEvent>("移除了用户后", LogEnum.DevConsole,
                                                action: message => {
                    _dicByLoginName.Remove(message.Target.LoginName);
                    OnPropertyChanged(nameof(List));
                }, location: this.GetType());
                foreach (var item in NTMinerRoot.Instance.UserSet.AsEnumerable())
                {
                    _dicByLoginName.Add(item.LoginName, new UserViewModel(item));
                }
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Пример #28
0
            protected override void Init()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                _localIps = GetLocalIps();
                RaiseEvent(new LocalIpSetInitedEvent());
#if DEBUG
                // 将近300毫秒
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(Init)}");
                }
#endif
            }
Пример #29
0
        public void BenchmarkTest2()
        {
            // 1秒钟约1200次压缩,原数据大小106kb
            byte[] rawData = File.ReadAllBytes(Path.Combine(TestUtil.DataDirFullName, "clientDatas.json"));

            NTStopwatch.Start();

            for (int i = 0; i < 1200; i++)
            {
                byte[] _ = GZipUtil.Compress(rawData);
            }

            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }
Пример #30
0
        public void BenchmarkTest1()
        {
            // 非常快,无性能问题,即使不是返回null值的单元测试程序下也非常快
            int n = 10000;

            Assert.IsNull(Assembly.GetEntryAssembly());
            Assert.IsTrue(DevMode.IsInUnitTest);
            NTStopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                _ = Assembly.GetEntryAssembly();
            }
            var elapsedMilliseconds = NTStopwatch.Stop();

            Console.WriteLine(elapsedMilliseconds);
        }