Introduce def as a trial. Fixup of timeit.

This commit is contained in:
Christoffer Lerno
2023-04-21 16:03:28 +02:00
parent edd2f1c717
commit c847650579
6 changed files with 50 additions and 9 deletions

View File

@@ -1,12 +1,27 @@
module test;
import std::time;
import std::io;
public macro timeit(#call)
def foo = write;
def Int = int;
macro @timeit(#call)
{
Time t = time::current();
typeof(#call) result = #call;
TimeDiff diff = time::current() - t;
libc::printf("'%s' took %f ms\n", $stringify(#call), diff * 1000);
Clock t = clock::now();
var result = #call;
io::printfn("'%s' took %d ns", $stringify(#call), t.mark());
return result;
}
fn int write()
{
for (int i = 0; i < 1000; i++) io::printf("%d", i);
io::printn();
return 0;
}
fn void main()
{
@timeit(write());
}