| Новости | FAQ | Авторы | Документация | В действии | Библиотека |
| Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
egr 27.05.2005 07:53
Значится так, - я проверил это в .NET. Эксперимент ставил чистый, т.е. проверял однократный поиск в тексте размером 500K.D:\CSharp\RegexpText\bin\Debug>RegexpText.exe microserfs.txt Modernist String result is: True. Time in milliseconds taken: 8,73770269685114 Regexp result is: True. Time in milliseconds taken: 1,45968272503908Вот иходник теста:
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Beeline.MOM;
namespace RegexpText
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage is RegexpText.exe <file> <pattern>");
return;
}
ElapsedTimeMilliseconds timer = new ElapsedTimeMilliseconds();
string text = GetTestText(args[0]);
if (text == null)
{
Console.WriteLine("File not found or empty");
return;
}
// String functions
timer.Begin();
bool found = (text.IndexOf(args[1]) >= 0);
timer.End();
Console.WriteLine("String result is: {0}. Time in milliseconds taken: {1}", found, timer.Elapsed);
// Regexp
Regex regex = new Regex(args[1], RegexOptions.None);
timer.Begin();
found = regex.IsMatch(text);
timer.End();
Console.WriteLine("Regexp result is: {0}. Time in milliseconds taken: {1}", found, timer.Elapsed);
}
static string GetTestText(string file)
{
StreamReader r = null;
string result = null;
try
{
r = new StreamReader(file, Encoding.ASCII);
result = r.ReadToEnd();
}
catch(ArgumentException e)
{
Trace.WriteLine(e.ToString());
}
catch(FileNotFoundException e)
{
Trace.WriteLine(e.ToString());
}
catch(DirectoryNotFoundException e)
{
Trace.WriteLine(e.ToString());
}
catch(IOException e)
{
Trace.WriteLine(e.ToString());
}
catch(OutOfMemoryException e)
{
Trace.WriteLine(e.ToString());
}
finally
{
if (r != null)
{
r.Close();
}
}
return result;
}
}
}Пусть не пугает использование Beeline.MOM - это я просто взял из своего текущего проекта библиотечку (сам написал) в которой есть классы-обертки для замера времени использующие Win32 API.