1
我需要知道多長時間(平均),需要將單個消息發送到隊列,因此我發送了1000,然後將總數除以1000 t get平均。如何使用秒錶來測量平均循環迭代的平均值
然而,這個控制檯應用程序需要大約5-10分鐘,並在最後總毫秒它是一個非常奇怪的數字,如100或400.而部門總是0.我從字面上拿我的手錶,應用程序需要5到10分鐘
我做錯了什麼來衡量這一點?
static void Main(string[] args)
{
string queueConnectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
QueueClient queueClientEmpresa = QueueClient.CreateFromConnectionString(queueConnectionString, "CapatechSaasApp");
try
{
Console.WriteLine("Testing sending millions of messages");
int i = 0;
// Create new stopwatch
Stopwatch stopwatch = new Stopwatch();
// Begin timing
stopwatch.Start();
while (i < 1000)
{
Empresa empresa = new Empresa()
{
Nombre = "Empresa:" + i,
NIT = "xx",
NombreRepresentanteLegal = "xx",
TelefonoRepresentanteLegal = "xx",
NombreContacto = "x",
TelefonoContacto = "x"
};
i++;
BrokeredMessage message = new BrokeredMessage(JsonConvert.SerializeObject(empresa));
message.Properties.Add("Operation", "Add");
message.Properties.Add("Tipo", "Empresa");
queueClientEmpresa.Send(message);
//string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
//Console.WriteLine("Press key to continue");
//Console.ReadKey();
//ReceiveMessagesEmpresa(connectionString);
}
stopwatch.Stop();
Console.WriteLine("Time elapsed milliseconds: {0}", stopwatch.Elapsed.Milliseconds.ToString());
Console.WriteLine("Time elapsed milliseconds/1000: {0}", (stopwatch.Elapsed.Milliseconds/1000).ToString());
Console.ReadKey();
}
catch (Exception ex)
{
throw ex;
}
}
http://screencast.com/t/fjcFRbf2jM
哈哈! :( 非常感謝 –
嗨@EstebanV,作爲答案艾米特給你適合你的需求,你不應該將它標記爲接受答案...? – Shnugo
是的,但你必須等待幾分鐘才能接受答案快速 –