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. a puzzle for timing method

a puzzle for timing method

Scheduled Pinned Locked Moved C#
questioncsshelp
6 Posts 4 Posters 0 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.
  • D Offline
    D Offline
    dragon_yue
    wrote on last edited by
    #1

    public interface IncDec { void Increment(); void Decrement(); } public class MyIncDec : IncDec { private int x; public MyIncDec(int x) { this.x = x; } public void Increment() { this.x++; } public void Decrement() { this.x--; } } Part 1: Implement a class which can be used to measure how long each invocation of the Increment and Decrement method takes (in milliseconds) and prints out this information. The class should fit in more or less transparently with existing clients of the IncDec interface. Part 2: Imagine you need to do something similar (timing of method calls) for many places in an application. What other ideas come to mind, e.g. could you propose other ideas for getting timing information more conveniently? I got this question need to answer, it is simple, just something confused to me. hope anyone can help me. btw, what "The class should fit in more or less transparently with existing clients of the IncDec interface. " means?

    L B L 3 Replies Last reply
    0
    • D dragon_yue

      public interface IncDec { void Increment(); void Decrement(); } public class MyIncDec : IncDec { private int x; public MyIncDec(int x) { this.x = x; } public void Increment() { this.x++; } public void Decrement() { this.x--; } } Part 1: Implement a class which can be used to measure how long each invocation of the Increment and Decrement method takes (in milliseconds) and prints out this information. The class should fit in more or less transparently with existing clients of the IncDec interface. Part 2: Imagine you need to do something similar (timing of method calls) for many places in an application. What other ideas come to mind, e.g. could you propose other ideas for getting timing information more conveniently? I got this question need to answer, it is simple, just something confused to me. hope anyone can help me. btw, what "The class should fit in more or less transparently with existing clients of the IncDec interface. " means?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      you need CLR Profiler for that : http://msdn.microsoft.com/en-us/library/ms979205.aspx[^]

      1 Reply Last reply
      0
      • D dragon_yue

        public interface IncDec { void Increment(); void Decrement(); } public class MyIncDec : IncDec { private int x; public MyIncDec(int x) { this.x = x; } public void Increment() { this.x++; } public void Decrement() { this.x--; } } Part 1: Implement a class which can be used to measure how long each invocation of the Increment and Decrement method takes (in milliseconds) and prints out this information. The class should fit in more or less transparently with existing clients of the IncDec interface. Part 2: Imagine you need to do something similar (timing of method calls) for many places in an application. What other ideas come to mind, e.g. could you propose other ideas for getting timing information more conveniently? I got this question need to answer, it is simple, just something confused to me. hope anyone can help me. btw, what "The class should fit in more or less transparently with existing clients of the IncDec interface. " means?

        B Offline
        B Offline
        Bekjong
        wrote on last edited by
        #3

        dragon_yue wrote:

        I got this question need to answer, it is simple, just something confused to me. hope anyone can help me. btw, what "The class should fit in more or less transparently with existing clients of the IncDec interface. " means?

        I suppose your teacher (this is homework, right?) means to give you a hint. If you create a new class that inherits MyIncDec and call the base classes methods, you can use this class instead of the orignal and have a place to put your performance timing code without disturbing MyIncDec's existing users.

        Standards are great! Everybody should have one!

        D 1 Reply Last reply
        0
        • D dragon_yue

          public interface IncDec { void Increment(); void Decrement(); } public class MyIncDec : IncDec { private int x; public MyIncDec(int x) { this.x = x; } public void Increment() { this.x++; } public void Decrement() { this.x--; } } Part 1: Implement a class which can be used to measure how long each invocation of the Increment and Decrement method takes (in milliseconds) and prints out this information. The class should fit in more or less transparently with existing clients of the IncDec interface. Part 2: Imagine you need to do something similar (timing of method calls) for many places in an application. What other ideas come to mind, e.g. could you propose other ideas for getting timing information more conveniently? I got this question need to answer, it is simple, just something confused to me. hope anyone can help me. btw, what "The class should fit in more or less transparently with existing clients of the IncDec interface. " means?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, this is a stupid assignment. In order to make it a realistic problem, one would need to measure a method containing hundred or more instructions to start with, not a single increment. The code required to transparently measure the duration of an increment will probably use a derived class, virtual methods, and a StopWatch. As such it will be much slower than the original increment itself, so the result is bound to be inaccurate (on top of being utterly irrelevant). :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          D 1 Reply Last reply
          0
          • B Bekjong

            dragon_yue wrote:

            I got this question need to answer, it is simple, just something confused to me. hope anyone can help me. btw, what "The class should fit in more or less transparently with existing clients of the IncDec interface. " means?

            I suppose your teacher (this is homework, right?) means to give you a hint. If you create a new class that inherits MyIncDec and call the base classes methods, you can use this class instead of the orignal and have a place to put your performance timing code without disturbing MyIncDec's existing users.

            Standards are great! Everybody should have one!

            D Offline
            D Offline
            dragon_yue
            wrote on last edited by
            #5

            its not homework, I konw its simple. thanks your answer. do you think the new class inherit from interface or that class. which one is better

            1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, this is a stupid assignment. In order to make it a realistic problem, one would need to measure a method containing hundred or more instructions to start with, not a single increment. The code required to transparently measure the duration of an increment will probably use a derived class, virtual methods, and a StopWatch. As such it will be much slower than the original increment itself, so the result is bound to be inaccurate (on top of being utterly irrelevant). :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


              D Offline
              D Offline
              dragon_yue
              wrote on last edited by
              #6

              I understand. it is stupid one. thanks

              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