using System.Diagnostics;
public static Stopwatch TimedFor(Action action, Int32 loops)
var sw = new Stopwatch();
for (int i = 0; i < loops; ++i)
private static void BoulalMethod()
for (int i = 1; i < n; i++)
for (int j = n; j > i; j--)
for (int j = 0; j < i * 2 - 1; j++)
result = result + Environment.NewLine;
private static void HichamMethod()
for (int i = 0; i < n; i++)
result = result + new string(' ', n - 1 - i);
for (int j = 0; j < i + i - 2; j++)
result = result + Environment.NewLine;
public static void Main(string[] args)
var sw = TimedFor(BoulalMethod, 10000);
var sw2 = TimedFor(HichamMethod, 10000);
Console.WriteLine("Time taken BOULAL: {0}ms", sw.Elapsed.TotalMilliseconds);
Console.WriteLine("Time taken BOUCHIKHI: {0}ms", sw2.Elapsed.TotalMilliseconds);