Time a function: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 235:
0;
}</lang>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
Line 670 ⟶ 671:
return 0;
}</lang>
 
=={{header|C++}}==
<lang cpp>#include <ctime>
#include <iostream>
using namespace std;
 
int identity(int x) { return x; }
int sum(int num) {
for (int i = 0; i < 1000000; i++)
num += i;
return num;
 
double time_it(int (*action)(int), int arg) {
clock_t start_time = clock();
action(arg);
clock_t finis_time = clock();
return ((double) (finis_time - start_time)) / CLOCKS_PER_SEC;
 
int main() {
cout << "Identity(4) takes " << time_it(identity, 4) << " seconds." << endl;
cout << "Sum(4) takes " << time_it(sum, 4) << " seconds." << endl;
return 0;
}</lang>
 
===Example===
Identity(4) takes 0 seconds.
Sum(4) takes 0.01 seconds.
 
=={{header|C sharp|C#}}==
Line 753 ⟶ 725:
Output:
DoSomething() took 1071,5408ms
 
=={{header|C++}}==
<lang cpp>#include <ctime>
#include <iostream>
using namespace std;
 
int identity(int x) { return x; }
int sum(int num) {
for (int i = 0; i < 1000000; i++)
num += i;
return num;
 
double time_it(int (*action)(int), int arg) {
clock_t start_time = clock();
action(arg);
clock_t finis_time = clock();
return ((double) (finis_time - start_time)) / CLOCKS_PER_SEC;
 
int main() {
cout << "Identity(4) takes " << time_it(identity, 4) << " seconds." << endl;
cout << "Sum(4) takes " << time_it(sum, 4) << " seconds." << endl;
return 0;
}</lang>
 
===Example===
Identity(4) takes 0 seconds.
Sum(4) takes 0.01 seconds.
 
=={{header|Clojure}}==
Line 878 ⟶ 879:
println(`Counting to $count takes ${(finish-start)//1000000}ms`)
}</lang>
 
=={{header|Elena}}==
{{trans|C#}}
Line 947 ⟶ 949:
23,24,25,26,27|...]}
</lang>
 
=={{header|Euphoria}}==
<lang euphoria>atom t
Line 1,735 ⟶ 1,738:
# outputs "Sum(4) takes 0.280000 seconds."</lang>
 
=={{header|Perl 6}}==
Follows modern trend toward measuring wall-clock time, since CPU time is becoming rather ill-defined in the age of multicore, and doesn't reflect IO overhead in any case.
<lang perl6>my $start = now;
(^100000).pick(1000);
say now - $start;</lang>
{{out}}
<pre>0.02301709</pre>
=={{header|Phix}}==
Measures wall-clock time. On Windows the resolution is about 15ms. The elapsed function makes things more human-readable, eg 720 (seconds) => 12 minutes
Line 1,830 ⟶ 1,826:
0.820712 Seconds
</pre>
 
 
=={{header|PureBasic}}==
Line 1,990 ⟶ 1,985:
(time (fact 5000))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
Follows modern trend toward measuring wall-clock time, since CPU time is becoming rather ill-defined in the age of multicore, and doesn't reflect IO overhead in any case.
<lang perl6>my $start = now;
(^100000).pick(1000);
say now - $start;</lang>
{{out}}
<pre>0.02301709</pre>
 
=={{header|Raven}}==
Line 2,291 ⟶ 2,295:
. timer_test 1000
1: 1.01 / 1 = 1.0140</lang>
 
 
=={{header|Swift}}==
Line 2,475 ⟶ 2,478:
End Sub</lang>{{out}}<pre>1000 times Identity(1) takes 0 seconds
1000 times Sum(1) takes 296 seconds</pre>
 
=={{header|Wart}}==
<lang python>time 1+1
10,333

edits