C Online Compiler
Example: Simple Call Counter in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Simple Call Counter #include <stdio.h> // Global counter for calls static long long total_function_calls = 0; void my_function_to_monitor() { total_function_calls++; // Simulate some work done by the function // For example, printf("."); } int main() { // Step 1: Call the function multiple times printf("Simulating calls to my_function_to_monitor...\n"); for (int i = 0; i < 1000000; i++) { my_function_to_monitor(); } // Step 2: Report the total number of calls printf("Total calls to my_function_to_monitor: %lld\n", total_function_calls); printf("\nResetting counter and simulating again for 500,000 calls...\n"); total_function_calls = 0; // Resetting for a new measurement for (int i = 0; i < 500000; i++) { my_function_to_monitor(); } printf("Total calls to my_function_to_monitor: %lld\n", total_function_calls); return 0; }
Output
Clear
ADVERTISEMENTS