From b4742c67b1bb2bbaae6c9a439ff67c15f0c3c2bc Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Sun, 7 Jun 2015 21:13:46 +0900 Subject: [PATCH] =?UTF-8?q?TabInformations=E3=81=AE=E3=83=99=E3=83=B3?= =?UTF-8?q?=E3=83=81=E3=83=9E=E3=83=BC=E3=82=AF=E7=94=A8=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Benchmark/TabInformationsBenchmark.cs | 123 ++++++++++++++++++ OpenTween.Tests/OpenTween.Tests.csproj | 1 + 2 files changed, 124 insertions(+) create mode 100644 OpenTween.Tests/Benchmark/TabInformationsBenchmark.cs diff --git a/OpenTween.Tests/Benchmark/TabInformationsBenchmark.cs b/OpenTween.Tests/Benchmark/TabInformationsBenchmark.cs new file mode 100644 index 000000000..77008f484 --- /dev/null +++ b/OpenTween.Tests/Benchmark/TabInformationsBenchmark.cs @@ -0,0 +1,123 @@ +// OpenTween - Client of Twitter +// Copyright (c) 2015 kim_upsilon (@kim_upsilon) +// All rights reserved. +// +// This file is part of OpenTween. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program. If not, see , or write to +// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +// Boston, MA 02110-1301, USA. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace OpenTween.Benchmark +{ + public class TabInformationsBenchmark + { + private TabInformations tabinfo; + + public TabInformationsBenchmark() + { + this.tabinfo = Activator.CreateInstance(typeof(TabInformations), true) as TabInformations; + + // TabInformation.GetInstance() で取得できるようにする + var field = typeof(TabInformations).GetField("_instance", + BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField); + field.SetValue(null, this.tabinfo); + + // 標準のタブを追加 + this.tabinfo.AddTab("Recent", MyCommon.TabUsageType.Home, null); + this.tabinfo.AddTab("Reply", MyCommon.TabUsageType.Mentions, null); + this.tabinfo.AddTab("DM", MyCommon.TabUsageType.DirectMessage, null); + this.tabinfo.AddTab("Favorites", MyCommon.TabUsageType.Favorites, null); + } + + [Fact] + [Trait("Type", "Benchmark")] + public void DistributeBenchmark_MoveMatches() + { + // MyTab1: name_000 から name_099 までのスクリーンネームにマッチ + var filtersQuery = + from x in Enumerable.Range(0, 100) + select new PostFilterRule + { + FilterName = "name_" + x.ToString("000"), + MoveMatches = true, + }; + var tab1 = AddFilterTab("MyTab1", filtersQuery.ToArray()); + + // 25% の確率で MyTab1 にヒットするツイートを 500 件生成 + var randStatusId = new Random(); + var postsQuery = + from x in Enumerable.Range(0, 500) + select new PostClass + { + StatusId = (long)randStatusId.Next() << 32 | (uint)randStatusId.Next(), + ScreenName = "name_" + x.ToString("000"), + }; + // postsQuery を 100 回実行する => 50,000 件 + var posts = Enumerable.Range(0, 100).Select(x => postsQuery).SelectMany(x => x) + .OrderBy(x => x.StatusId).ToArray(); + + long addPostTime, distributeTime, updateTime; + var watch = new Stopwatch(); + + // 測定1: TabInformations.AddPost() + watch.Start(); + foreach (var post in posts) + this.tabinfo.AddPost(post); + watch.Stop(); + addPostTime = watch.ElapsedMilliseconds; + + // 測定2: TabInformation.DistributePosts() + watch.Restart(); + this.tabinfo.DistributePosts(); + watch.Stop(); + distributeTime = watch.ElapsedMilliseconds; + + // 測定3: TabInformations.SubmitUpdate() + string _ = null; + PostClass[] __ = null; + bool ___ = false; + watch.Restart(); + this.tabinfo.SubmitUpdate(ref _, ref __, ref ___, ref ___, isUserStream: false); + watch.Stop(); + updateTime = watch.ElapsedMilliseconds; + + Assert.Equal(50000, this.tabinfo.Posts.Count); + Assert.Equal(10000, tab1.AllCount); + + Console.WriteLine("AddPost: " + addPostTime); + Console.WriteLine("DistributePosts: " + distributeTime); + Console.WriteLine("SubmitUpdate: " + updateTime); + } + + private TabClass AddFilterTab(string tabName, PostFilterRule[] filterRules) + { + this.tabinfo.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null); + + var tab = this.tabinfo.Tabs[tabName]; + tab.FilterArray = filterRules; + + return tab; + } + } +} diff --git a/OpenTween.Tests/OpenTween.Tests.csproj b/OpenTween.Tests/OpenTween.Tests.csproj index 3c4a6b02e..129bdfef7 100644 --- a/OpenTween.Tests/OpenTween.Tests.csproj +++ b/OpenTween.Tests/OpenTween.Tests.csproj @@ -63,6 +63,7 @@ +

AltStyle によって変換されたページ (->オリジナル) /