Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuong Hoang <lhoang@live.com>2014-10-20 18:25:59 +0400
committerLuong Hoang <lhoang@live.com>2014-10-20 18:25:59 +0400
commit5bc5d3d69c55e952290cdfcf8b03dbb35f812031 (patch)
tree3ef383d1ba4f15732e4fc072cc8218c26b2304b9 /cs_test
parent74ccaefa89f0a30867f3bcc3ccba375532e67a5c (diff)
added clock file with timing code
Diffstat (limited to 'cs_test')
-rw-r--r--cs_test/ExploreClock.cs79
1 files changed, 79 insertions, 0 deletions
diff --git a/cs_test/ExploreClock.cs b/cs_test/ExploreClock.cs
new file mode 100644
index 00000000..68767999
--- /dev/null
+++ b/cs_test/ExploreClock.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MultiWorldTesting;
+
+namespace cs_test
+{
+ public class ExploreClock
+ {
+ public static void Clock()
+ {
+ float epsilon = .2f;
+ int policyParams = 1003;
+ string uniqueKey = "clock";
+ int numFeatures = 1000;
+ int numIter = 10;
+ int numWarmup = 3;
+ int numInteractions = 2000;
+ uint numActions = 10;
+ string otherContext = null;
+
+ double timeInit = 0, timeChoose = 0, timeSerializedLog = 0, timeTypedLog = 0;
+
+ System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
+ for (int iter = 0; iter < numIter + numWarmup; iter++)
+ {
+ watch.Restart();
+
+ MwtExplorer mwt = new MwtExplorer("test");
+ mwt.InitializeEpsilonGreedy<int>(epsilon, new StatefulPolicyDelegate<int>(SampleStatefulPolicyFunc), policyParams, numActions);
+
+ timeInit += (iter < numWarmup) ? 0 : watch.Elapsed.TotalMilliseconds;
+
+ FEATURE[] f = new FEATURE[numFeatures];
+ for (int i = 0; i < numFeatures; i++)
+ {
+ f[i].Id = (uint)i + 1;
+ f[i].Value = 0.5f;
+ }
+
+ watch.Restart();
+
+ CONTEXT context = new CONTEXT(f, otherContext);
+
+ for (int i = 0; i < numInteractions; i++)
+ {
+ mwt.ChooseAction(uniqueKey, context);
+ }
+
+ timeChoose += (iter < numWarmup) ? 0 : watch.Elapsed.TotalMilliseconds;
+
+ watch.Restart();
+
+ string interactions = mwt.GetAllInteractionsAsString();
+
+ timeSerializedLog += (iter < numWarmup) ? 0 : watch.Elapsed.TotalMilliseconds;
+
+ for (int i = 0; i < numInteractions; i++)
+ {
+ mwt.ChooseAction(uniqueKey, context);
+ }
+
+ watch.Restart();
+
+ mwt.GetAllInteractions();
+
+ timeTypedLog += (iter < numWarmup) ? 0 : watch.Elapsed.TotalMilliseconds;
+ }
+ Console.WriteLine("--- PER ITERATION ---");
+ Console.WriteLine("# iterations: {0}, # interactions: {1}, # context features {2}", numIter, numInteractions, numFeatures);
+ Console.WriteLine("Init: {0} micro", timeInit * 1000 / numIter);
+ Console.WriteLine("Choose Action: {0} micro", timeChoose * 1000 / (numIter * numInteractions));
+ Console.WriteLine("Get Serialized Log: {0} micro", timeSerializedLog * 1000 / numIter);
+ Console.WriteLine("Get Typed Log: {0} micro", timeTypedLog * 1000 / numIter);
+ Console.WriteLine("--- TOTAL TIME: {0} micro", (timeInit + timeChoose + timeSerializedLog + timeTypedLog) * 1000);
+ }
+ }
+}