The
time command can be used to time a single statement.
> n := 2^109-1;
> time Factorization(n);
[<745988807, 1>, <870035986098720987332873, 1>]
Time: 0.149
Alternatively, we can extract the current time t and use
Cputime.
This method can be used to time the execution of several statements.
> m := 2^111-1;
> n := 2^113-1;
> t := Cputime();
> Factorization(m);
[<7, 1>, <223, 1>, <321679, 1>, <26295457, 1>, <319020217, 1>, <616318177, 1>]
> Factorization(n);
[<3391, 1>, <23279, 1>, <65993, 1>, <1868569, 1>, <1066818132868207, 1>]
> Cputime(t);
0.121
We illustrate a simple use of
vtime with
vprint within a function.
> function MyFunc(G)
> vprint User1: "Computing order...";
> vtime User1: o := #G;
> return o;
> end function;
> SetVerbose("User1", 0);
> MyFunc(Sym(4));
24
> SetVerbose("User1", 1);
> MyFunc(Sym(4));
Computing order...
Time: 0.000
24
In this example, we first time a matrix multiplication statement
in the default single-threaded mode, so the time which is
printed (or returned by the second Time call) is the CPU time.
> X := Random(MatrixRing(GF(5), 10000));
> time P := X*X; // single thread, normal CPU time
Time: 4.060
> T := Time(); P := X*X; Time(T); // similar with Time() function
4.060
Then we specify 8 threads for the multiplication algorithm, and
note that the time has the tag [r] appended, to indicate
that the time which is printed (or returned by the second Time call)
is the real time.
> SetNthreads(8);
> time P := X*X; // multi-threads, so real time shown by [r]
Time: 1.050[r]
> T := Time(); P := X*X; Time(T); // similar with Time() function
1.050[r]
[Next][Prev] [Right] [Left] [Up] [Index] [Root]