## Counted Function (CountedFunction)

버전 1.0.3.0 (8.09 KB) 작성자:
Class to define functions in a way that facilitates counting the number of function calls/evaluations.

다운로드 수: 7

업데이트 날짜: 2023/1/15

GitHub에서 호스트

# `CountedFunction` Class to define functions in a way that facilitates counting the number of function calls/evaluations.

## Usage

`[fc,count] = CountedFunction.count_function_calls(f)`

## Description

`[fc,count] = CountedFunction.count_function_calls(f)` takes a function handle, `f`, and returns a function handle `fc` and a counter function `count`. `fc` performs the same function evaluation as `f` (it is just wrapped around a `CountedFunction` object which calls `f` directly). Calling the counter function (i.e. `count()`) will return the current number of function calls.

## Note

• For simple functions, such as `f = @(x) x^2`, this can severely slow down function calls (by a factor of ~20).
• For complicated functions that have a long evaluation time to begin with, this performance hit is negligible.

## Basic Example

See more examples in `Examples.mlx`.

```% define the function
f = @(x) x^2;

% new function handle that counts the number of function evaluations
[f,count] = CountedFunction.count_function_calls(f);

% evaluates the function 1000 times
for i = 1:1000
f(0);
end

% prints the number of function evaluations
count()```
```ans =

1000```
```% evaluates the function another 1000 times
for i = 1:1000
f(0);
end

% prints the number of function evaluations again
count()```
```ans =

2000```

### 인용 양식

Tamas Kis (2023). Counted Function (CountedFunction) (https://github.com/tamaskis/CountedFunction-MATLAB/releases/tag/v1.0.3), GitHub. 검색됨 .

개발 환경: R2022a
모든 릴리스와 호환
##### 플랫폼 호환성
Windows macOS Linux

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.3.0

See release notes for this release on GitHub: https://github.com/tamaskis/CountedFunction-MATLAB/releases/tag/v1.0.3

1.0.2.0

See release notes for this release on GitHub: https://github.com/tamaskis/CountedFunction-MATLAB/releases/tag/v1.0.2

1.0.1

See release notes for this release on GitHub: https://github.com/tamaskis/CountedFunction-MATLAB/releases/tag/v1.0.1

1.0.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.