Click here to Skip to main content
15,885,278 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regex for String.Contains Pin
amrok2amrokk10-May-12 23:32
amrok2amrokk10-May-12 23:32 
AnswerRe: Regex for String.Contains Pin
Pete O'Hanlon10-May-12 23:48
mvePete O'Hanlon10-May-12 23:48 
GeneralRe: Regex for String.Contains Pin
Manfred Rudolf Bihy11-May-12 0:28
professionalManfred Rudolf Bihy11-May-12 0:28 
GeneralRe: Regex for String.Contains Pin
PIEBALDconsult11-May-12 3:24
mvePIEBALDconsult11-May-12 3:24 
AnswerRe: Regex for String.Contains Pin
OriginalGriff11-May-12 3:52
mveOriginalGriff11-May-12 3:52 
GeneralRe: Regex for String.Contains Pin
amrok2amrokk11-May-12 4:28
amrok2amrokk11-May-12 4:28 
GeneralRe: Regex for String.Contains Pin
OriginalGriff11-May-12 4:55
mveOriginalGriff11-May-12 4:55 
GeneralRe: Regex for String.Contains Pin
amrok2amrokk11-May-12 5:07
amrok2amrokk11-May-12 5:07 
Hi! I've changed the code and got these results
00:00:00.2780085
00:00:00.2824236
00:00:00.2805873
for Regex

00:00:00.3233195
00:00:00.3238453
00:00:00.3248080
for Contains

C#
namespace RegexTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        List<string> _data;

        public Window1()
        {
            InitializeComponent();

            _data = new List<string>(50000);

            Random rand = new Random();
            byte[] data = new byte[4000];

            //int count = _data.Count;

            for (int i = 0; i < 50000; i++)
            {
                rand.NextBytes(data);
                _data.Add(Convert.ToBase64String(data));
            }
        }

        private void buttonTestRegex_Click(object sender, RoutedEventArgs e)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            {

                Regex regex = new Regex("99");
                int count = _data.Count;

                int match = 0;

                for (int i = 0; i < count; i++)
                    match += regex.IsMatch(_data[i]) ? 1 : 0;

            }
            sw.Stop();

            this.textBoxRegex.Text = sw.Elapsed.ToString();
        }

        private void buttonTestString_Click(object sender, RoutedEventArgs e)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            {
                Regex regex = new Regex("99");
                int count = _data.Count;

                int match = 0;

                for (int i = 0; i < count; i++)
                    match += _data[i].Contains("99") ? 1 : 0;
            }
            sw.Stop();

            this.textBoxString.Text = sw.Elapsed.ToString();
        }
    }
}


I use x86 processor, .NET 3.5.
GeneralRe: Regex for String.Contains Pin
PIEBALDconsult11-May-12 5:30
mvePIEBALDconsult11-May-12 5:30 
GeneralRe: Regex for String.Contains Pin
amrok2amrokk11-May-12 5:59
amrok2amrokk11-May-12 5:59 
GeneralRe: Regex for String.Contains Pin
PIEBALDconsult11-May-12 5:09
mvePIEBALDconsult11-May-12 5:09 
GeneralRe: Regex for String.Contains Pin
jschell11-May-12 13:46
jschell11-May-12 13:46 
AnswerRe: Regex for String.Contains Pin
BobJanova11-May-12 3:58
BobJanova11-May-12 3:58 
QuestionGraphicsDeviceServce Pin
Philip Solomon See10-May-12 13:08
Philip Solomon See10-May-12 13:08 
AnswerRe: GraphicsDeviceServce Pin
Richard MacCutchan10-May-12 22:02
mveRichard MacCutchan10-May-12 22:02 
Questionsend data from google api v3 javascript to c# Pin
mrx10010-May-12 11:12
mrx10010-May-12 11:12 
AnswerRe: send data from google api v3 javascript to c# Pin
Gerry Schmitz10-May-12 13:01
mveGerry Schmitz10-May-12 13:01 
AnswerRe: send data from google api v3 javascript to c# Pin
loyal ginger11-May-12 4:34
loyal ginger11-May-12 4:34 
GeneralRe: send data from google api v3 javascript to c# Pin
mrx10011-May-12 10:50
mrx10011-May-12 10:50 
GeneralRe: send data from google api v3 javascript to c# Pin
loyal ginger14-May-12 3:33
loyal ginger14-May-12 3:33 
Questiondrawing on one form and display it on another form Pin
borrasanjay10-May-12 9:44
borrasanjay10-May-12 9:44 
AnswerRe: drawing on one form and display it on another form Pin
Luc Pattyn10-May-12 11:15
sitebuilderLuc Pattyn10-May-12 11:15 
GeneralRe: drawing on one form and display it on another form Pin
borrasanjay10-May-12 14:04
borrasanjay10-May-12 14:04 
AnswerRe: drawing on one form and display it on another form Pin
Luc Pattyn10-May-12 14:26
sitebuilderLuc Pattyn10-May-12 14:26 
GeneralRe: drawing on one form and display it on another form Pin
Ravi Bhavnani11-May-12 9:05
professionalRavi Bhavnani11-May-12 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.