• R/O
  • HTTP
  • SSH
  • HTTPS

open-tween: 提交

開発に使用するリポジトリ


Commit MetaInfo

修訂b4742c67b1bb2bbaae6c9a439ff67c15f0c3c2bc (tree)
時間2015-06-07 21:14:32
作者Kimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

TabInformationsのベンチマーク用のテストコードを追加

Change Summary

差異

--- /dev/null
+++ b/OpenTween.Tests/Benchmark/TabInformationsBenchmark.cs
@@ -0,0 +1,123 @@
1+// OpenTween - Client of Twitter
2+// Copyright (c) 2015 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3+// All rights reserved.
4+//
5+// This file is part of OpenTween.
6+//
7+// This program is free software; you can redistribute it and/or modify it
8+// under the terms of the GNU General Public License as published by the Free
9+// Software Foundation; either version 3 of the License, or (at your option)
10+// any later version.
11+//
12+// This program is distributed in the hope that it will be useful, but
13+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+// for more details.
16+//
17+// You should have received a copy of the GNU General Public License along
18+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20+// Boston, MA 02110-1301, USA.
21+
22+using System;
23+using System.Collections.Generic;
24+using System.Diagnostics;
25+using System.Linq;
26+using System.Reflection;
27+using System.Text;
28+using System.Threading.Tasks;
29+using Xunit;
30+
31+namespace OpenTween.Benchmark
32+{
33+ public class TabInformationsBenchmark
34+ {
35+ private TabInformations tabinfo;
36+
37+ public TabInformationsBenchmark()
38+ {
39+ this.tabinfo = Activator.CreateInstance(typeof(TabInformations), true) as TabInformations;
40+
41+ // TabInformation.GetInstance() で取得できるようにする
42+ var field = typeof(TabInformations).GetField("_instance",
43+ BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField);
44+ field.SetValue(null, this.tabinfo);
45+
46+ // 標準のタブを追加
47+ this.tabinfo.AddTab("Recent", MyCommon.TabUsageType.Home, null);
48+ this.tabinfo.AddTab("Reply", MyCommon.TabUsageType.Mentions, null);
49+ this.tabinfo.AddTab("DM", MyCommon.TabUsageType.DirectMessage, null);
50+ this.tabinfo.AddTab("Favorites", MyCommon.TabUsageType.Favorites, null);
51+ }
52+
53+ [Fact]
54+ [Trait("Type", "Benchmark")]
55+ public void DistributeBenchmark_MoveMatches()
56+ {
57+ // MyTab1: name_000 から name_099 までのスクリーンネームにマッチ
58+ var filtersQuery =
59+ from x in Enumerable.Range(0, 100)
60+ select new PostFilterRule
61+ {
62+ FilterName = "name_" + x.ToString("000"),
63+ MoveMatches = true,
64+ };
65+ var tab1 = AddFilterTab("MyTab1", filtersQuery.ToArray());
66+
67+ // 25% の確率で MyTab1 にヒットするツイートを 500 件生成
68+ var randStatusId = new Random();
69+ var postsQuery =
70+ from x in Enumerable.Range(0, 500)
71+ select new PostClass
72+ {
73+ StatusId = (long)randStatusId.Next() << 32 | (uint)randStatusId.Next(),
74+ ScreenName = "name_" + x.ToString("000"),
75+ };
76+ // postsQuery を 100 回実行する => 50,000 件
77+ var posts = Enumerable.Range(0, 100).Select(x => postsQuery).SelectMany(x => x)
78+ .OrderBy(x => x.StatusId).ToArray();
79+
80+ long addPostTime, distributeTime, updateTime;
81+ var watch = new Stopwatch();
82+
83+ // 測定1: TabInformations.AddPost()
84+ watch.Start();
85+ foreach (var post in posts)
86+ this.tabinfo.AddPost(post);
87+ watch.Stop();
88+ addPostTime = watch.ElapsedMilliseconds;
89+
90+ // 測定2: TabInformation.DistributePosts()
91+ watch.Restart();
92+ this.tabinfo.DistributePosts();
93+ watch.Stop();
94+ distributeTime = watch.ElapsedMilliseconds;
95+
96+ // 測定3: TabInformations.SubmitUpdate()
97+ string _ = null;
98+ PostClass[] __ = null;
99+ bool ___ = false;
100+ watch.Restart();
101+ this.tabinfo.SubmitUpdate(ref _, ref __, ref ___, ref ___, isUserStream: false);
102+ watch.Stop();
103+ updateTime = watch.ElapsedMilliseconds;
104+
105+ Assert.Equal(50000, this.tabinfo.Posts.Count);
106+ Assert.Equal(10000, tab1.AllCount);
107+
108+ Console.WriteLine("AddPost: " + addPostTime);
109+ Console.WriteLine("DistributePosts: " + distributeTime);
110+ Console.WriteLine("SubmitUpdate: " + updateTime);
111+ }
112+
113+ private TabClass AddFilterTab(string tabName, PostFilterRule[] filterRules)
114+ {
115+ this.tabinfo.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null);
116+
117+ var tab = this.tabinfo.Tabs[tabName];
118+ tab.FilterArray = filterRules;
119+
120+ return tab;
121+ }
122+ }
123+}
--- a/OpenTween.Tests/OpenTween.Tests.csproj
+++ b/OpenTween.Tests/OpenTween.Tests.csproj
@@ -63,6 +63,7 @@
6363 <Compile Include="AnyOrderComparer.cs" />
6464 <Compile Include="Api\ApiLimitTest.cs" />
6565 <Compile Include="Api\TwitterApiStatusTest.cs" />
66+ <Compile Include="Benchmark\TabInformationsBenchmark.cs" />
6667 <Compile Include="BingTest.cs" />
6768 <Compile Include="Connection\NetworkingTest.cs" />
6869 <Compile Include="EmojiFormatterTest.cs" />
Show on old repository browser