Thread overview
Timing Code - Read Time-Stamp Counter + Message?
Mar 17, 2005
AEon
Mar 17, 2005
AEon
Mar 17, 2005
Ben Hinkle
Mar 17, 2005
AEon
March 17, 2005
Using the example in the documentation: Timing Code
i.e. a Read Time-Stamp Counter:

<code>
   import std.stdio;
March 17, 2005
3rd try... WTH?

Timing Code - Read Time-Stamp Counter + Message?

Using the example in the documentation: Timing Code
i.e. a Read Time-Stamp Counter:

<code>
   import std.stdio;
   class Timer3
   {
       static long getCount()
       {
           asm
           {
               naked   ;
               rdtsc   ;
               ret     ;
           }
       }

       long starttime;

       this( char[] message ) { starttime = getCount(); } // added "char[]
message"

       ~this( char[] message )                            // added "char[]
message"
       {
           writef("\n%.*s\n\n", message);                 // Adding extra info
           writefln("Fine ASM Timer:   Elapsed time = %d",
                       getCount() - starttime);
      }
   }
   void main()
   {
       auto Timer3 t3 = new Timer3("Fine call from main()");
       for (int i = 0; i < 10_000_000; i++) // 10_000_000 -> 15 ms
       {
       }
   }
</code>

The timer will calculate the time the code needs to execute the code in the scope it was called. In this example in "main { }".

But when I tried to pass an extra message to the class contructors and destructors, I get massive amounts of warnings:

   test5.d(19): found 'char' when expecting ')'
   test5.d(19): semicolon expected following function declaration
   test5.d(19): Declaration expected, not '['
   test5.d(22): found 'Fine ASM Timer:   Elapsed time = %d' when expecting ')'
   test5.d(22): no identifier for declarator writefln
   test5.d(22): multiple declarations must have the same type,
                  not writefln and writefln()
   test5.d(22): semicolon expected following function declaration
   test5.d(22): Declaration expected, not '-'

   test5.d(24): unrecognized declaration

What am I doing wrong?

AEon
March 17, 2005
>       ~this( char[] message )    // added "char[] message"

~this can't take any inputs. You need to store the message you passed to the ctor in a data member in the class like you store the starttime.


March 17, 2005
In article <d1c7ed$15q3$1@digitaldaemon.com>, Ben Hinkle says...
>
>>       ~this( char[] message )    // added "char[] message"
>
>~this can't take any inputs. You need to store the message you passed to the ctor in a data member in the class like you store the starttime.

Thanx...

<code>
	class Timer3
	{
	    static long getCount()
	    {
	        asm
	        {
	            naked   ;
	            rdtsc   ;
	            ret     ;
	        }
	    }
	    long starttime;
	    char[] message;
	    this() { starttime = getCount(); }
	    this( char[] s )
	    {
	        this();
	        message = s;
	    }
	    ~this()
	    {
	        writef("\n  %s\n\n", message );
	        writefln("   Fine ASM Timer:   Elapsed time = %d",
	                 getCount() - starttime);
	    }
	}
	void main()
	{
	    auto Timer3 t3 = new Timer3("Fine call from main()");
	}
</code>

Seems to work fine now :)

AEon