-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluation.cs
133 lines (128 loc) · 5.31 KB
/
evaluation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace evaluation
{
class Program
{
static Dictionary<string, int> one_process(string app_path, string cmd)
{
Dictionary<string, int> freq_dict = new Dictionary<string, int>();
System.Diagnostics.Process exep = new System.Diagnostics.Process();
exep.StartInfo.Arguments = cmd;
exep.StartInfo.CreateNoWindow = false;
exep.StartInfo.RedirectStandardOutput = true;
exep.StartInfo.UseShellExecute = false;
exep.StartInfo.FileName = app_path;
exep.Start();
StreamReader reader = exep.StandardOutput;
string line = reader.ReadLine();
string first_line = line;
while (!reader.EndOfStream)
{
line = reader.ReadLine().Trim();
if (line == "")
break;
string[] words = line.Split('\t');
freq_dict[words[0]] = int.Parse(words[1]);
}
exep.WaitForExit();
exep.Close();
return freq_dict;
}
static Dictionary<string, float> one_process_count_char(string app_path, string cmd)
{
Dictionary<string, float> freq_dict = new Dictionary<string, float>();
System.Diagnostics.Process exep = new System.Diagnostics.Process();
exep.StartInfo.Arguments = cmd;
exep.StartInfo.CreateNoWindow = false;
exep.StartInfo.RedirectStandardOutput = true;
exep.StartInfo.UseShellExecute = false;
exep.StartInfo.FileName = app_path;
exep.Start();
StreamReader reader = exep.StandardOutput;
string line = reader.ReadLine();
string first_line = line;
float sum = 0;
while (!reader.EndOfStream)
{
line = reader.ReadLine().Trim();
if (line == "")
break;
string[] words = line.Split('\t');
freq_dict[words[0]] = float.Parse(words[1].Trim('%'));
sum += freq_dict[words[0]];
}
List<string> keys = new List<string>(freq_dict.Keys);
foreach (string k in keys)
{
freq_dict[k] /= sum;
}
exep.WaitForExit();
exep.Close();
return freq_dict;
}
[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
static extern bool QueryPerformanceCounter(ref long count);
[System.Runtime.InteropServices.DllImport("Kernel32.dll")]
static extern bool QueryPerformanceFrequency(ref long count);
static void Main(string[] args)
{
string path = "D:/ASE/word_count/WordFrequency - Reference Implementation/Release/WordFrequencyFSharpFramework.exe";
string cmd = "-p 3 D:/ASE/word_count/test_file/pride-and-prejudice.txt";
int times = 9;
long count = 0;
long count1 = 0;
long freq = 0;
double result = 0;
QueryPerformanceFrequency(ref freq);
QueryPerformanceCounter(ref count);
var ta_result = one_process(path, cmd);
for (int i = 0; i < times; i ++)
ta_result = one_process(path, cmd);
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
Console.WriteLine("time TA:" + result.ToString());
path = "D:/ASE/word_count/word_count/word_count/bin/Release/word_count.exe";
QueryPerformanceFrequency(ref freq);
QueryPerformanceCounter(ref count);
var my_result = one_process(path, cmd);
for (int i = 0; i < times; i++)
my_result = one_process(path, cmd);
QueryPerformanceCounter(ref count1);
count = count1 - count;
result = (double)(count) / (double)freq;
Console.WriteLine("time MY:" + result.ToString());
List<string> keys = new List<string>();
string outfile = "D:/ASE/word_count/compare.txt";
StreamWriter sw = new StreamWriter(outfile);
foreach (string k in ta_result.Keys.OrderByDescending(o => ta_result[o]))
{
var ta_num = ta_result[k];
float my_num;
if (my_result.ContainsKey(k))
{
my_num = my_result[k];
my_result.Remove(k);
}
else
my_num = 0;
sw.WriteLine("{0, 40}\t{1}\t{2}", k, ta_num.ToString(), my_num.ToString());
if(ta_num!=my_num)
Console.WriteLine("{0, 40}\t{1}\t{2}", k, ta_num.ToString(), my_num.ToString());
}
foreach(string k in my_result.Keys.OrderByDescending(o => my_result[o]))
{
var ta_num = 0;
var my_num = my_result[k];
sw.WriteLine("{0, 40}\t{1}\t{2}", k, ta_num.ToString(), my_num.ToString());
Console.WriteLine("{0, 40}\t{1}\t{2}", k, ta_num.ToString(), my_num.ToString());
}
sw.Close();
}
}
}