Skip to content

Instantly share code, notes, and snippets.

@VinixGonzalez
Last active October 16, 2019 00:28
Show Gist options
  • Save VinixGonzalez/fa761d236f485c5fbcab5fc164ef5b8f to your computer and use it in GitHub Desktop.
Save VinixGonzalez/fa761d236f485c5fbcab5fc164ef5b8f to your computer and use it in GitHub Desktop.
Stopwatch
namespace Stopwatch01
{
class Program
{
static void Main(string[] args)
{
// Instancia um objeto do tipo Stopwatch
Stopwatch watch = new Stopwatch();
// Conexão com o banco de dados de teste
using (ApplicationContext db = new ApplicationContext())
{
// Inicia o cronômetro com o método Start()
watch.Start();
// Busca todos os registros da tabela de testes
var testes = db.Teste.AsNoTracking().ToList();
// Para o cronômetro
watch.Stop();
// Output do total de registros
Console.WriteLine($"Total: {testes.Count} registros.");
}
// Através da propriedade .Elapsed.TotalSeconds, obtemos o tempo total em segundos
Console.WriteLine($"{watch.Elapsed.TotalSeconds} segundos.");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment