using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using MongoDB.Driver; namespace MongoTest { class Program { static void Main(string[] args) { var stopwatch = new Stopwatch(); stopwatch.Start(); var settings = new MongoClientSettings { Server = new MongoServerAddress("localhost", 27017), ConnectTimeout = TimeSpan.FromSeconds(2), }; var client = new MongoClient(settings); try { client.GetServer().Connect(); } catch (Exception e) { Console.WriteLine(e); } stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); // Non-existing machine stopwatch.Reset(); stopwatch.Start(); settings = new MongoClientSettings { //TODO - change IP Server = new MongoServerAddress("XXX.XXX.XXX.XX", 27017), ConnectTimeout = TimeSpan.FromSeconds(2), }; client = new MongoClient(settings); try { client.GetServer().Connect(); } catch (Exception e) { Console.WriteLine(e); } stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); } } }