|
Exemple 16-21 extrait du chapitre Bibliothèques de classes
Exemple 16-20< > Exemple 17-1
Cet exemple peut être compilé avec la ligne de commande: csc.exe /target:exe Exemple_16_21.cs Erreurs: 1 Avertissements: 0 Remarque:
Exemple_16_21.cs
using System;
using System.Text.RegularExpressions;
using CompiledExpressions;
public class Program {
const int NLOOP = 1000000;
const string str = "abcdefghijklmnopqrstuvwxyz";
static void Main() {
bool b;
Regex regex1 = new Regex("^[^0-9]*$");
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < NLOOP; i++)
b = regex1.IsMatch(str);
Console.WriteLine("Sans précompilation:{0}", sw.Elapsed );
sw = Stopwatch.StartNew();
PasDeChiffres regex2 = new PasDeChiffres();
for (int i = 0; i < NLOOP; i++)
b = regex2.IsMatch(str);
Console.WriteLine("Avec précompilation:{0}", sw.Elapsed );
}
}
Copyright Patrick Smacchia 2006 2007
|