cputoc

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.0, Creation date: 2017-08-01, Last change: 2025-08-18

similar to toc but uses the cpu timer



See Also: cputic

Example Illustration

 missing image of cputoc

Syntax

tc=cputoc

Output Parameter

tc: Elapsed cpu time in seconds

Examples


tic; for i=10000000000; x=cos(pi/16); end; toc
cputic; for i=10000000000; x=cos(pi/16); end; cputoc
f=@() cos(pi/3), timeit(f)




Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, cputoc, is part of the SolidGeometry library and is used to measure the elapsed CPU time since a previous call to cputic. It is similar to the built-in toc function but specifically uses the CPU timer.

Input Parameters

The function does not take any input parameters.

Global Variables

Output

Algorithm Steps

  1. The function accesses the global variable ctic_tic to retrieve the stored CPU time from the last cputic call.
  2. It calculates the elapsed CPU time by subtracting ctic_tic from the current CPU time obtained using cputime.
  3. If the function is called without an output argument, it prints the elapsed CPU time to the console using fprintf.

Example Usage

The function can be used in conjunction with cputic to measure the CPU time taken by a block of code:

tic; for i=1:10000000000; x=cos(pi/16); end; toc
cputic; for i=1:10000000000; x=cos(pi/16); end; cputoc
f=@() cos(pi/3); timeit(f)

In this example, both toc and cputoc are used to measure the time taken by a loop, but cputoc specifically measures the CPU time.

Algorithm explaination created using ChatGPT on 2025-08-18 22:20. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21