Sistem
paket "sistem";
The sistem
package contains a couple of utility system functions. These include:
- tempiraj
- tempirajNano
- zatvoriProces
tempiraj
The tempiraj
function is used to measure the execution time of a provided function in milliseconds.
- takes:
- fn - a block of code wrapped inside a lambda function (
funkcija
)
- fn - a block of code wrapped inside a lambda function (
- returns: time it takes to execute provided block of code, expressed in milliseconds (
broj
) - special cases: none
var vrijeme = tempiraj(funkcija(){ za svako (x od 1 do 1_000_000){ x^2; } }); ispis("Execution time: ", vrijeme, "ms");
Output: Execution time: 489ms
Note that the lambda function you pass as the argument should not take any arguments itself, nor return anything.
tempirajNano
The tempirajNano
function is used to measure the execution time of a provided function in nanoseconds.
- takes:
- fn - a block of code wrapped inside a lambda function (
funkcija
)
- fn - a block of code wrapped inside a lambda function (
- returns: time it takes to execute provided block of code, expressed in nanoseconds (
broj
) - special cases: none
paket "sistem"; var vrijeme = tempirajNano(funkcija(){ za svako (x od 1 do 1_000_000){ x^2; } }); ispis("Execution time: ", vrijeme, " nanoseconds");
Output: Execution time: 2.979184E8 nanoseconds
The function behaves exactly the same as tempiraj
, except for the unit of time it returns.
zatvoriProces
The zatvoriProces
function terminates the currently running process with a provided status.
- takes:
- status - status code to exit process with (
broj
)
- status - status code to exit process with (
- returns: the function doesn’t return
- special cases: none
zatvoriProces(0);
Process finished with exit code 0
zatvoriProces(-1);
Process finished with exit code -1
By convention, any non-zero exit code indicates an abnormal termination.