From WikiChip
Difference between revisions of "mirc/identifiers/$ticks"
< mirc‎ | identifiers

m
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{mirc title|$ticks identifier}}'''$ticks''' retrieves the number of [[milliseconds]] that have elapsed since the system was [[uptime|started]]. $ticks is most often used in [[benchmarking]].
 
{{mirc title|$ticks identifier}}'''$ticks''' retrieves the number of [[milliseconds]] that have elapsed since the system was [[uptime|started]]. $ticks is most often used in [[benchmarking]].
 +
  
 
== Details ==
 
== Details ==
Line 26: Line 27:
 
}
 
}
 
</source>
 
</source>
 +
 +
As an example of the limited precision of $ticks, you can see from the following command that during an interval of 1000 milliseconds where the current $ticks result is continually added to a tokenized list, that it does not create a list of 1000 items, but instead creates a list of approximately 65 numbers which are generally separated by around 15-16.
 +
 +
<pre>
 +
//var %end $ticks + 1000 , %list | while ($ticks < %end) var %list $addtok(%list,$ticks,32) | echo -a $numtok(%list,32) items: %list
 +
</pre>
 +
 +
This means that scripts which use $ticks to create a unique name for a timer or a COM call can easily fail. If you need a fast way to create a unique string, you can use something like:
 +
<pre>
 +
alias unique { hinc -m unique sequential | return $hget(unique,sequential) }
 +
</pre>
 +
 +
... where $unique always returns a different sequential number as long as the hashtable is not tampered with, and if the number does not reach $calc(2^53)<press tab key>.
  
 
== Compatibility ==
 
== Compatibility ==
Line 31: Line 45:
  
 
== See also ==
 
== See also ==
* [[List of identifiers - mIRC|List of identifiers]]
 
* [[List of commands - mIRC|List of commands]]
 
 
* {{mIRC|$ctime}}
 
* {{mIRC|$ctime}}
 
* {{mIRC|$timer}}
 
* {{mIRC|$timer}}
Line 41: Line 53:
 
* {{mIRC|$asctime}}
 
* {{mIRC|$asctime}}
 
* {{mIRC|/noop}}
 
* {{mIRC|/noop}}
{{mIRC identifier list}}
 
 
[[Category:mIRC identifiers|ticks]]
 

Latest revision as of 14:01, 5 February 2023

$ticks retrieves the number of milliseconds that have elapsed since the system was started. $ticks is most often used in benchmarking.


Details[edit]

The $ticks identifier is used to retrieves the current system uptime in milliseconds. The identifier is limited to the resolution of the system timer which is typically in the range of 10 milliseconds to 16 milliseconds. Prior to mIRC version 7.33 the $ticks identifier used the GetTickCount() function which meant the value $ticks returned would wrap around to zero after 49.71 days. In 7.33 the $ticks identifier was switched to use the GetTickCount64() function, eliminating this issue (which wraps around once every 584.9 million years).

Synopsis[edit]

$ticks

Parameters[edit]

None

Properties[edit]

None

Example[edit]

; time how long it takes to execute an empty loop 10,000 times.
Alias example {
  var %ticks = $ticks, %x = 10000
  
  while (%x) {
    dec %x
  }
  
  echo -a 10,000 empty iterations took: $calc($ticks - %ticks) ms.
}

As an example of the limited precision of $ticks, you can see from the following command that during an interval of 1000 milliseconds where the current $ticks result is continually added to a tokenized list, that it does not create a list of 1000 items, but instead creates a list of approximately 65 numbers which are generally separated by around 15-16.

//var %end $ticks + 1000 , %list | while ($ticks < %end) var %list $addtok(%list,$ticks,32) | echo -a $numtok(%list,32) items: %list

This means that scripts which use $ticks to create a unique name for a timer or a COM call can easily fail. If you need a fast way to create a unique string, you can use something like:

alias unique { hinc -m unique sequential | return $hget(unique,sequential) }

... where $unique always returns a different sequential number as long as the hashtable is not tampered with, and if the number does not reach $calc(2^53)<press tab key>.

Compatibility[edit]

Added: mIRC v4.7
Added on: 09 Dec 1996
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See also[edit]