Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Benchmark not Benching

Benchmark not Benching

Scheduled Pinned Locked Moved C#
helpquestion
9 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reelix
    wrote on last edited by
    #1

    I'm attempting to code a mini processor benchmarking program(For fun :D) The problem is... Marks are always 0 :wtf: marks is a global int variable string myWord = "1234567890"; StreamWriter sw = new StreamWriter(@"C:\benchMe.txt"); for (int j = 0; j < 1000; j++) { sw.Write(myWord); } sw.Flush(); sw.Close(); timer1.Interval = 1; MessageBox.Show("Test Ready!"); StreamReader sr = new StreamReader(@"C:\benchMe.txt"); string bob = sr.ReadToEnd(); sr.Close(); timer1.Enabled = true; // Begin Benchmark Console.WriteLine(bob); // There's a LARGE delay here. timer1.Enabled = false; MessageBox.Show("Marks on Test: " + marks); marks = 0; private void timer1_Tick(object sender, EventArgs e) { marks++; } Any ideas? I was thinking that maybe the "Lag" was canceling the increment on the timer, or something... Any ideas, anyone? :)

    R J C 3 Replies Last reply
    0
    • R Reelix

      I'm attempting to code a mini processor benchmarking program(For fun :D) The problem is... Marks are always 0 :wtf: marks is a global int variable string myWord = "1234567890"; StreamWriter sw = new StreamWriter(@"C:\benchMe.txt"); for (int j = 0; j < 1000; j++) { sw.Write(myWord); } sw.Flush(); sw.Close(); timer1.Interval = 1; MessageBox.Show("Test Ready!"); StreamReader sr = new StreamReader(@"C:\benchMe.txt"); string bob = sr.ReadToEnd(); sr.Close(); timer1.Enabled = true; // Begin Benchmark Console.WriteLine(bob); // There's a LARGE delay here. timer1.Enabled = false; MessageBox.Show("Marks on Test: " + marks); marks = 0; private void timer1_Tick(object sender, EventArgs e) { marks++; } Any ideas? I was thinking that maybe the "Lag" was canceling the increment on the timer, or something... Any ideas, anyone? :)

      R Offline
      R Offline
      Razvan Dimescu
      wrote on last edited by
      #2

      have you started the timer? timer1.Start(), timer1.Stop()

      blog

      R 1 Reply Last reply
      0
      • R Razvan Dimescu

        have you started the timer? timer1.Start(), timer1.Stop()

        blog

        R Offline
        R Offline
        Reelix
        wrote on last edited by
        #3

        :omg: :sigh: :bashhead: -_- Ok, now it works (Once...) Benchmark code modified to: private void button2_Click(object sender, EventArgs e) { StreamReader sr = new StreamReader(@"C:\benchMe.txt"); string bob = sr.ReadToEnd(); sr.Close(); timer1.Start(); Console.WriteLine(bob); timer1.Stop(); MessageBox.Show("Marks on Test: " + marks); marks = 0; } First click displays marks, second click -> x click displays 0. So close.... :)

        R 1 Reply Last reply
        0
        • R Reelix

          :omg: :sigh: :bashhead: -_- Ok, now it works (Once...) Benchmark code modified to: private void button2_Click(object sender, EventArgs e) { StreamReader sr = new StreamReader(@"C:\benchMe.txt"); string bob = sr.ReadToEnd(); sr.Close(); timer1.Start(); Console.WriteLine(bob); timer1.Stop(); MessageBox.Show("Marks on Test: " + marks); marks = 0; } First click displays marks, second click -> x click displays 0. So close.... :)

          R Offline
          R Offline
          Razvan Dimescu
          wrote on last edited by
          #4

          glad it helped

          blog

          1 Reply Last reply
          0
          • R Reelix

            I'm attempting to code a mini processor benchmarking program(For fun :D) The problem is... Marks are always 0 :wtf: marks is a global int variable string myWord = "1234567890"; StreamWriter sw = new StreamWriter(@"C:\benchMe.txt"); for (int j = 0; j < 1000; j++) { sw.Write(myWord); } sw.Flush(); sw.Close(); timer1.Interval = 1; MessageBox.Show("Test Ready!"); StreamReader sr = new StreamReader(@"C:\benchMe.txt"); string bob = sr.ReadToEnd(); sr.Close(); timer1.Enabled = true; // Begin Benchmark Console.WriteLine(bob); // There's a LARGE delay here. timer1.Enabled = false; MessageBox.Show("Marks on Test: " + marks); marks = 0; private void timer1_Tick(object sender, EventArgs e) { marks++; } Any ideas? I was thinking that maybe the "Lag" was canceling the increment on the timer, or something... Any ideas, anyone? :)

            J Offline
            J Offline
            J a a n s
            wrote on last edited by
            #5

            You have mentioned the timer interval as 1ms. If the interval is less than 15ms (sometimes this will be more according to the processor/hardware.) it is not going to perform correctly. This article will explain it clearly. Timer surprises, and how to avoid them[^]

            *jaans

            R 1 Reply Last reply
            0
            • J J a a n s

              You have mentioned the timer interval as 1ms. If the interval is less than 15ms (sometimes this will be more according to the processor/hardware.) it is not going to perform correctly. This article will explain it clearly. Timer surprises, and how to avoid them[^]

              *jaans

              R Offline
              R Offline
              Reelix
              wrote on last edited by
              #6

              D: Never knew that! Thanks alot!!! - Reelix

              1 Reply Last reply
              0
              • R Reelix

                I'm attempting to code a mini processor benchmarking program(For fun :D) The problem is... Marks are always 0 :wtf: marks is a global int variable string myWord = "1234567890"; StreamWriter sw = new StreamWriter(@"C:\benchMe.txt"); for (int j = 0; j < 1000; j++) { sw.Write(myWord); } sw.Flush(); sw.Close(); timer1.Interval = 1; MessageBox.Show("Test Ready!"); StreamReader sr = new StreamReader(@"C:\benchMe.txt"); string bob = sr.ReadToEnd(); sr.Close(); timer1.Enabled = true; // Begin Benchmark Console.WriteLine(bob); // There's a LARGE delay here. timer1.Enabled = false; MessageBox.Show("Marks on Test: " + marks); marks = 0; private void timer1_Tick(object sender, EventArgs e) { marks++; } Any ideas? I was thinking that maybe the "Lag" was canceling the increment on the timer, or something... Any ideas, anyone? :)

                C Offline
                C Offline
                c2423
                wrote on last edited by
                #7

                I read this a couple of times, and I'm not 100% sure what all of it is doing, so forgive me if Im a little off the mark with this... Have you looked at System.Diagnostics.Stopwatch at all? If what you are going for is performance testing you could have something like: const int NumberOfTests = 1000000; System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch(); s.Start(); for (int i = 0; i < NumberOfTests; i++) { //Code to test goes here! } s.Stop(); MessageBox.Show(s.ElapsedMilliseconds.ToString()); (Rinse and repeat for multiple benchmarks) Hope that helps, Chris

                R 1 Reply Last reply
                0
                • C c2423

                  I read this a couple of times, and I'm not 100% sure what all of it is doing, so forgive me if Im a little off the mark with this... Have you looked at System.Diagnostics.Stopwatch at all? If what you are going for is performance testing you could have something like: const int NumberOfTests = 1000000; System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch(); s.Start(); for (int i = 0; i < NumberOfTests; i++) { //Code to test goes here! } s.Stop(); MessageBox.Show(s.ElapsedMilliseconds.ToString()); (Rinse and repeat for multiple benchmarks) Hope that helps, Chris

                  R Offline
                  R Offline
                  Reelix
                  wrote on last edited by
                  #8

                  Thanks alot! It perfected everything :D YAY! IsHappy("Reelix") == true; :D

                  C 1 Reply Last reply
                  0
                  • R Reelix

                    Thanks alot! It perfected everything :D YAY! IsHappy("Reelix") == true; :D

                    C Offline
                    C Offline
                    c2423
                    wrote on last edited by
                    #9

                    Glad to have helped! :) Chris

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups