Usage := module() export TimeMemoryGC, TimeMemoryPrint, TimeMemoryHeader; TimeMemoryGC := proc(ex :: uneval, loops :: posint := 1) local alloc,used,gct,st; description "return the time, bytes used, bytes allocated, and gc cycles " "required to evaluate `ex' `loops' times"; (used,alloc,gct) := kernelopts('bytesused', 'bytesalloc','gctimes'); st := time(); to loops do eval(ex); end do; ( time()-st , (kernelopts('bytesused', 'bytesalloc', 'gctimes')) - (used,alloc,gct) ); end proc: TimeMemoryPrint := proc(p :: And(name, Or(procedure,And(`module`,appliable))) , { argseq := NULL , loops :: posint := 1 } , $ ) local dur,used,alloc,gct; description "print the time, Mbytes used, Mbytes allocated,, and gc cycles " "required to execute `p(arglst)' `loops' times"; (dur,used,alloc,gct) := TimeMemoryGC( p(argseq), loops ); printf("%6.2f" "%10.2f" "%12.2f" "%10d" " %A" "\n" , dur , convert(used, 'units', 'bytes', 'mebibytes') , convert(alloc, 'units', 'bytes', 'mebibytes') , gct , p ); end proc: TimeMemoryHeader := proc() printf("time (s) used (MB) alloc (MB) gctimes proc\n"); printf("-------- --------- ---------- ------- ----\n"); end proc; end module: # Save the module in ~/etc/maple/Usage.mla savelibname := sprintf("%s/etc/maple/Usage.mla", getenv("HOME")): use FileTools in if Exists(savelibname) then Remove(savelibname); end if; end use; LibraryTools:-Create(savelibname): LibraryTools:-Save(Usage):