Calcul le temps d'exécution d'un script PHP

Classe pour calculer le temps d'exécution d'un script et affiche le résultat en microsecondes.


Information sur les mises à jour

Dernière mise à jour :

24 Août 2019
fonctionnement du code vérifié

15 Fév 2026
refactoring du code en PHP 8

18 264  vues
Compatibilité du code
PHP 8
  code classé dans   Classes
  code source classé dans   Classes
 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
                    
<?php
/*------------------------------*/
/*
Titre : Calcul le temps d'exécution d'un script PHP

Auteur : Eric Potvin
Date édition : 23 Sept 2005
Date mise a jour : 24 Aout 2019

Rapport de la maj:
- fonctionnement du code vérifié
Date mise a jour : 15 Fev 2026

Rapport de la maj:
- refactoring du code en PHP 8
*/
/*------------------------------*/

declare(strict_types=1);

/**
* Classe moderne pour mesurer le temps d'exécution en PHP 8.3+
*
* Améliorations par rapport à l'ancienne méthode :
* - Utilisation de hrtime() (nanoseconde) au lieu de microtime()
* - Typed properties et return types
* - Support de multiples timers simultanés
* - Format de sortie flexible
* - Precision configurable
*/
class ExecutionTimer
{
private array $timers = [];
private array $results = [];

/**
* Démarre un timer
*/
public function start(string $name = 'default'): void
{
$this->timers[$name] = hrtime(true);
}

/**
* Arrête un timer et retourne le temps écoulé
*
* @return float Temps en secondes
*/
public function stop(string $name = 'default'): float
{
if (!isset($this->timers[$name])) {
throw new RuntimeException("Timer '$name' n'a pas été démarré");
}

$elapsed = (hrtime(true) - $this->timers[$name]) / 1_000_000_000;
$this->results[$name] = $elapsed;
unset($this->timers[$name]);

return $elapsed;
}

/**
* Obtient le temps écoulé sans arrêter le timer
*/
public function elapsed(string $name = 'default'): float
{
if (!isset($this->timers[$name])) {
throw new RuntimeException("Timer '$name' n'a pas été démarré");
}

return (hrtime(true) - $this->timers[$name]) / 1_000_000_000;
}

/**
* Formate le temps en unité appropriée
*/
public function format(float $seconds, int $precision = 4): string
{
return match (true) {
$seconds < 0.000001 => round($seconds * 1_000_000_000, $precision) .
' ns',
$seconds < 0.001 => round($seconds * 1_000_000, $precision) . ' ?s',
$seconds < 1 => round($seconds * 1000, $precision) . ' ms',
$seconds < 60 => round($seconds, $precision) . ' s',
default => sprintf('%d min %0.2f s', floor($seconds / 60), $seconds
% 60)
};
}

/**
* Obtient tous les résultats enregistrés
*/
public function getResults(): array
{
return $this->results;
}

/**
* Affiche un résumé formaté
*/
public function displaySummary(): void
{
echo "\n" . str_repeat('=', 60) . "\n";
echo "RÉSUMÉ DES TEMPS D'EXÉCUTION\n";
echo str_repeat('=', 60) . "\n";

foreach ($this->results as $name => $time) {
printf("%-30s : %s\n", $name, $this->format($time));
}

echo str_repeat('=', 60) . "\n\n";
}
}

// ============================================
// EXEMPLES D'UTILISATION
// ============================================

// Exemple 1 : Usage basique (ancien vs nouveau)
echo "=== EXEMPLE 1 : Usage Basique ===\n\n";

// ? ANCIEN CODE (microtime)
echo "Ancienne méthode (microtime) :\n";
$start_old = microtime(true);
sleep(1);
$end_old = microtime(true);
$execution_time_old = $end_old - $start_old;
echo "Temps : " . round($execution_time_old, 4) . " secondes\n\n";

// ? NOUVEAU CODE (hrtime)
echo "Nouvelle méthode (hrtime) :\n";
$timer = new ExecutionTimer();
$timer->start();
sleep(1);
$time = $timer->stop();
echo "Temps : " . $timer->format($time) . "\n\n";


// Exemple 2 : Multiples timers simultanés
echo "=== EXEMPLE 2 : Multiples Timers ===\n\n";

$timer = new ExecutionTimer();

$timer->start('boucle_1');
for ($i = 0; $i < 1000000; $i++) {
// Opération simple
}
$timer->stop('boucle_1');

$timer->start('boucle_2');
for ($i = 0; $i < 1000000; $i++) {
$x = $i * 2;
}
$timer->stop('boucle_2');

$timer->start('base_donnees_simulation');
usleep(5000); // Simule une requête DB
$timer->stop('base_donnees_simulation');

$timer->displaySummary();


// Exemple 3 : Mesure pendant l'exécution
echo "=== EXEMPLE 3 : Mesure en Temps Réel ===\n\n";

$timer = new ExecutionTimer();
$timer->start('longue_tache');

for ($i = 1; $i <= 5; $i++) {
usleep(200000); // 200ms
echo "Étape $i/5 - Temps écoulé : " . $timer->format($timer->elapsed(
'longue_tache')) . "\n";
}

$timer->stop('longue_tache');
echo "\n";


// Exemple 4 : Fonction helper simple
echo "=== EXEMPLE 4 : Fonction Helper ===\n\n";

/**
* Fonction helper pour mesurer rapidement une fonction
*/
function mesurer_execution(callable $fonction, string $nom = 'fonction'): float

{
$start = hrtime(true);
$fonction();
$elapsed = (hrtime(true) - $start) / 1_000_000_000;

$timer = new ExecutionTimer();
echo "$nom : " . $timer->format($elapsed) . "\n";

return $elapsed;
}

mesurer_execution(function() {
for ($i = 0; $i < 500000; $i++) {
$x = sqrt($i);
}
}, 'Calcul racine carrée');


// Exemple 5 : Comparaison de performances
echo "\n=== EXEMPLE 5 : Comparaison d'Algorithmes ===\n\n";

function bubble_sort(array $arr): array {
$n = count($arr);
for ($i = 0; $i < $n - 1; $i++) {
for ($j = 0; $j < $n - $i - 1; $j++) {
if ($arr[$j] > $arr[$j + 1]) {
[$arr[$j], $arr[$j + 1]] = [$arr[$j + 1], $arr[$j]];
}
}
}
return $arr;
}

$data = range(1, 100);
shuffle($data);

$timer = new ExecutionTimer();

// Test 1 : Bubble sort
$data_copy = $data;
$timer->start('bubble_sort');
bubble_sort($data_copy);
$timer->stop('bubble_sort');

// Test 2 : sort() natif
$data_copy = $data;
$timer->start('sort_natif');
sort($data_copy);
$timer->stop('sort_natif');

$timer->displaySummary();

// Calcul du gain
$bubble_time = $timer->getResults()['bubble_sort'];
$native_time = $timer->getResults()['sort_natif'];
$gain = ($bubble_time / $native_time);
echo "Le sort() natif est " . round($gain, 1) . "x plus rapide !\n\n";


// Exemple 6 : Classe avec auto-timer (pattern decorator)
echo "=== EXEMPLE 6 : Auto-Timer (Avancé) ===\n\n";

/**
* Trait pour ajouter automatiquement un timer à n'importe quelle méthode
*/
trait TimedExecution
{
private static ExecutionTimer $globalTimer;

public static function initTimer(): void
{
self::$globalTimer = new ExecutionTimer();
}

protected function timed(string $name, callable $callback): mixed
{
if (!isset(self::$globalTimer)) {
self::initTimer();
}

self::$globalTimer->start($name);
$result = $callback();
$time = self::$globalTimer->stop($name);

echo "?? $name : " . self::$globalTimer->format($time) . "\n";

return $result;
}
}

class DataProcessor
{
use TimedExecution;

public function process(array $data): array
{
return $this->timed('Traitement des données', function() use ($data) {
// Simulation traitement
usleep(100000);
return array_map(fn($x) => $x * 2, $data);
});
}

public function validate(array $data): bool
{
return $this->timed('Validation', function() use ($data) {
usleep(50000);
return count($data) > 0;
});
}
}

$processor = new DataProcessor();
$result = $processor->process([1, 2, 3, 4, 5]);
$valid = $processor->validate($result);

echo "\n";

?>
<?php
/*------------------------------*/
/*
Titre : Calcul le temps d'exécution d'un script PHP

Auteur : Eric Potvin
Date édition : 23 Sept 2005
Date mise a jour : 24 Aout 2019

Rapport de la maj:
- fonctionnement du code vérifié
Date mise a jour : 15 Fev 2026

Rapport de la maj:
- refactoring du code en PHP 8
*/
/*------------------------------*/

declare(strict_types=1);

/**
* Classe moderne pour mesurer le temps d'exécution en PHP 8.3+
*
* Améliorations par rapport à l'ancienne méthode :
* - Utilisation de hrtime() (nanoseconde) au lieu de microtime()
* - Typed properties et return types
* - Support de multiples timers simultanés
* - Format de sortie flexible
* - Precision configurable
*/
class ExecutionTimer
{
private array $timers = [];
private array $results = [];

/**
* Démarre un timer
*/
public function start(string $name = 'default'): void
{
$this->timers[$name] = hrtime(true);
}

/**
* Arrête un timer et retourne le temps écoulé
*
* @return float Temps en secondes
*/
public function stop(string $name = 'default'): float
{
if (!isset($this->timers[$name])) {
throw new RuntimeException("Timer '$name' n'a pas été démarré");
}

$elapsed = (hrtime(true) - $this->timers[$name]) / 1_000_000_000;
$this->results[$name] = $elapsed;
unset($this->timers[$name]);

return $elapsed;
}

/**
* Obtient le temps écoulé sans arrêter le timer
*/
public function elapsed(string $name = 'default'): float
{
if (!isset($this->timers[$name])) {
throw new RuntimeException("Timer '$name' n'a pas été démarré");
}

return (hrtime(true) - $this->timers[$name]) / 1_000_000_000;
}

/**
* Formate le temps en unité appropriée
*/
public function format(float $seconds, int $precision = 4): string
{
return match (true) {
$seconds < 0.000001 => round($seconds * 1_000_000_000, $precision) .
' ns',
$seconds < 0.001 => round($seconds * 1_000_000, $precision) . ' ?s',
$seconds < 1 => round($seconds * 1000, $precision) . ' ms',
$seconds < 60 => round($seconds, $precision) . ' s',
default => sprintf('%d min %0.2f s', floor($seconds / 60), $seconds
% 60)
};
}

/**
* Obtient tous les résultats enregistrés
*/
public function getResults(): array
{
return $this->results;
}

/**
* Affiche un résumé formaté
*/
public function displaySummary(): void
{
echo "\n" . str_repeat('=', 60) . "\n";
echo "RÉSUMÉ DES TEMPS D'EXÉCUTION\n";
echo str_repeat('=', 60) . "\n";

foreach ($this->results as $name => $time) {
printf("%-30s : %s\n", $name, $this->format($time));
}

echo str_repeat('=', 60) . "\n\n";
}
}

// ============================================
// EXEMPLES D'UTILISATION
// ============================================

// Exemple 1 : Usage basique (ancien vs nouveau)
echo "=== EXEMPLE 1 : Usage Basique ===\n\n";

// ? ANCIEN CODE (microtime)
echo "Ancienne méthode (microtime) :\n";
$start_old = microtime(true);
sleep(1);
$end_old = microtime(true);
$execution_time_old = $end_old - $start_old;
echo "Temps : " . round($execution_time_old, 4) . " secondes\n\n";

// ? NOUVEAU CODE (hrtime)
echo "Nouvelle méthode (hrtime) :\n";
$timer = new ExecutionTimer();
$timer->start();
sleep(1);
$time = $timer->stop();
echo "Temps : " . $timer->format($time) . "\n\n";


// Exemple 2 : Multiples timers simultanés
echo "=== EXEMPLE 2 : Multiples Timers ===\n\n";

$timer = new ExecutionTimer();

$timer->start('boucle_1');
for ($i = 0; $i < 1000000; $i++) {
// Opération simple
}
$timer->stop('boucle_1');

$timer->start('boucle_2');
for ($i = 0; $i < 1000000; $i++) {
$x = $i * 2;
}
$timer->stop('boucle_2');

$timer->start('base_donnees_simulation');
usleep(5000); // Simule une requête DB
$timer->stop('base_donnees_simulation');

$timer->displaySummary();


// Exemple 3 : Mesure pendant l'exécution
echo "=== EXEMPLE 3 : Mesure en Temps Réel ===\n\n";

$timer = new ExecutionTimer();
$timer->start('longue_tache');

for ($i = 1; $i <= 5; $i++) {
usleep(200000); // 200ms
echo "Étape $i/5 - Temps écoulé : " . $timer->format($timer->elapsed(
'longue_tache')) . "\n";
}

$timer->stop('longue_tache');
echo "\n";


// Exemple 4 : Fonction helper simple
echo "=== EXEMPLE 4 : Fonction Helper ===\n\n";

/**
* Fonction helper pour mesurer rapidement une fonction
*/
function mesurer_execution(callable $fonction, string $nom = 'fonction'): float

{
$start = hrtime(true);
$fonction();
$elapsed = (hrtime(true) - $start) / 1_000_000_000;

$timer = new ExecutionTimer();
echo "$nom : " . $timer->format($elapsed) . "\n";

return $elapsed;
}

mesurer_execution(function() {
for ($i = 0; $i < 500000; $i++) {
$x = sqrt($i);
}
}, 'Calcul racine carrée');


// Exemple 5 : Comparaison de performances
echo "\n=== EXEMPLE 5 : Comparaison d'Algorithmes ===\n\n";

function bubble_sort(array $arr): array {
$n = count($arr);
for ($i = 0; $i < $n - 1; $i++) {
for ($j = 0; $j < $n - $i - 1; $j++) {
if ($arr[$j] > $arr[$j + 1]) {
[$arr[$j], $arr[$j + 1]] = [$arr[$j + 1], $arr[$j]];
}
}
}
return $arr;
}

$data = range(1, 100);
shuffle($data);

$timer = new ExecutionTimer();

// Test 1 : Bubble sort
$data_copy = $data;
$timer->start('bubble_sort');
bubble_sort($data_copy);
$timer->stop('bubble_sort');

// Test 2 : sort() natif
$data_copy = $data;
$timer->start('sort_natif');
sort($data_copy);
$timer->stop('sort_natif');

$timer->displaySummary();

// Calcul du gain
$bubble_time = $timer->getResults()['bubble_sort'];
$native_time = $timer->getResults()['sort_natif'];
$gain = ($bubble_time / $native_time);
echo "Le sort() natif est " . round($gain, 1) . "x plus rapide !\n\n";


// Exemple 6 : Classe avec auto-timer (pattern decorator)
echo "=== EXEMPLE 6 : Auto-Timer (Avancé) ===\n\n";

/**
* Trait pour ajouter automatiquement un timer à n'importe quelle méthode
*/
trait TimedExecution
{
private static ExecutionTimer $globalTimer;

public static function initTimer(): void
{
self::$globalTimer = new ExecutionTimer();
}

protected function timed(string $name, callable $callback): mixed
{
if (!isset(self::$globalTimer)) {
self::initTimer();
}

self::$globalTimer->start($name);
$result = $callback();
$time = self::$globalTimer->stop($name);

echo "?? $name : " . self::$globalTimer->format($time) . "\n";

return $result;
}
}

class DataProcessor
{
use TimedExecution;

public function process(array $data): array
{
return $this->timed('Traitement des données', function() use ($data) {
// Simulation traitement
usleep(100000);
return array_map(fn($x) => $x * 2, $data);
});
}

public function validate(array $data): bool
{
return $this->timed('Validation', function() use ($data) {
usleep(50000);
return count($data) > 0;
});
}
}

$processor = new DataProcessor();
$result = $processor->process([1, 2, 3, 4, 5]);
$valid = $processor->validate($result);

echo "\n";

?>

Exemple :

 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
                    
<?php

declare(strict_types=1);

/**
* VERSION ULTRA-SIMPLE
* Pour ceux qui veulent juste mesurer rapidement
*/

// ============================================
// MÉTHODE 1 : La plus simple (1 ligne)
// ============================================

echo "=== MÉTHODE 1 : Ultra-Simple ===\n\n";

$start = hrtime(true);

// Votre code ici
sleep(1);

$temps = (hrtime(true) - $start) / 1_000_000_000;
echo "Temps d'exécution : " . round($temps, 4) . " secondes\n\n";


// ============================================
// MÉTHODE 2 : Avec formatage automatique
// ============================================

echo "=== MÉTHODE 2 : Avec Formatage ===\n\n";

function chrono(callable $fonction): void
{
$start = hrtime(true);
$fonction();
$temps = (hrtime(true) - $start) / 1_000_000_000;

// Formatage automatique
$formatted = match (true) {
$temps < 0.001 => round($temps * 1_000_000, 2) . ' ?s',
$temps < 1 => round($temps * 1000, 2) . ' ms',
default => round($temps, 4) . ' s'
};

echo "?? Temps : $formatted\n";
}

chrono(function() {
for ($i = 0; $i < 1000000; $i++) {
$x = $i * 2;
}
});

echo "\n";


// ============================================
// MÉTHODE 3 : Pour mesurer plusieurs parties
// ============================================

echo "=== MÉTHODE 3 : Multiples Mesures ===\n\n";

$timers = [];

// Démarrer un timer
function timer_start(string $nom): void
{
global $timers;
$timers[$nom] = hrtime(true);
}

// Arrêter et afficher
function timer_stop(string $nom): void
{
global $timers;
$temps = (hrtime(true) - $timers[$nom]) / 1_000_000_000;
echo "$nom : " . round($temps * 1000, 2) . " ms\n";
}

timer_start('Partie 1');
usleep(100000); // 100ms
timer_stop('Partie 1');

timer_start('Partie 2');
usleep(200000); // 200ms
timer_stop('Partie 2');

timer_start('Partie 3');
usleep(50000); // 50ms
timer_stop('Partie 3');

echo "\n";


// ============================================
// COMPARAISON : Ancien vs Nouveau
// ============================================

echo "=== COMPARAISON : microtime() vs hrtime() ===\n\n";

// ? ANCIEN (microtime - précision microseconde)
echo "Ancienne méthode :\n";
$debut = microtime(true);
usleep(1000); // 1ms
$fin = microtime(true);
echo "Temps : " . ($fin - $debut) . " secondes\n\n";

// ? NOUVEAU (hrtime - précision nanoseconde)
echo "Nouvelle méthode :\n";
$debut = hrtime(true);
usleep(1000); // 1ms
$fin = hrtime(true);
echo "Temps : " . (($fin - $debut) / 1_000_000_000) . " secondes\n";
echo "Précision : 1000x meilleure !\n\n";


// ============================================
// TEMPLATE À COPIER-COLLER
// ============================================

echo "=== TEMPLATE PRÊT À L'EMPLOI ===\n\n";

echo <<<'TEMPLATE'
// Copiez ce code dans vos scripts :

$start = hrtime(true);

// ===== VOTRE CODE ICI =====



// ===== FIN DE VOTRE CODE =====

$temps = (hrtime(true) - $start) / 1_000_000_000;
echo "Temps d'exécution : " . round($temps, 4) . " s\n";

TEMPLATE;

?>
<?php

declare(strict_types=1);

/**
* VERSION ULTRA-SIMPLE
* Pour ceux qui veulent juste mesurer rapidement
*/

// ============================================
// MÉTHODE 1 : La plus simple (1 ligne)
// ============================================

echo "=== MÉTHODE 1 : Ultra-Simple ===\n\n";

$start = hrtime(true);

// Votre code ici
sleep(1);

$temps = (hrtime(true) - $start) / 1_000_000_000;
echo "Temps d'exécution : " . round($temps, 4) . " secondes\n\n";


// ============================================
// MÉTHODE 2 : Avec formatage automatique
// ============================================

echo "=== MÉTHODE 2 : Avec Formatage ===\n\n";

function chrono(callable $fonction): void
{
$start = hrtime(true);
$fonction();
$temps = (hrtime(true) - $start) / 1_000_000_000;

// Formatage automatique
$formatted = match (true) {
$temps < 0.001 => round($temps * 1_000_000, 2) . ' ?s',
$temps < 1 => round($temps * 1000, 2) . ' ms',
default => round($temps, 4) . ' s'
};

echo "?? Temps : $formatted\n";
}

chrono(function() {
for ($i = 0; $i < 1000000; $i++) {
$x = $i * 2;
}
});

echo "\n";


// ============================================
// MÉTHODE 3 : Pour mesurer plusieurs parties
// ============================================

echo "=== MÉTHODE 3 : Multiples Mesures ===\n\n";

$timers = [];

// Démarrer un timer
function timer_start(string $nom): void
{
global $timers;
$timers[$nom] = hrtime(true);
}

// Arrêter et afficher
function timer_stop(string $nom): void
{
global $timers;
$temps = (hrtime(true) - $timers[$nom]) / 1_000_000_000;
echo "$nom : " . round($temps * 1000, 2) . " ms\n";
}

timer_start('Partie 1');
usleep(100000); // 100ms
timer_stop('Partie 1');

timer_start('Partie 2');
usleep(200000); // 200ms
timer_stop('Partie 2');

timer_start('Partie 3');
usleep(50000); // 50ms
timer_stop('Partie 3');

echo "\n";


// ============================================
// COMPARAISON : Ancien vs Nouveau
// ============================================

echo "=== COMPARAISON : microtime() vs hrtime() ===\n\n";

// ? ANCIEN (microtime - précision microseconde)
echo "Ancienne méthode :\n";
$debut = microtime(true);
usleep(1000); // 1ms
$fin = microtime(true);
echo "Temps : " . ($fin - $debut) . " secondes\n\n";

// ? NOUVEAU (hrtime - précision nanoseconde)
echo "Nouvelle méthode :\n";
$debut = hrtime(true);
usleep(1000); // 1ms
$fin = hrtime(true);
echo "Temps : " . (($fin - $debut) / 1_000_000_000) . " secondes\n";
echo "Précision : 1000x meilleure !\n\n";


// ============================================
// TEMPLATE À COPIER-COLLER
// ============================================

echo "=== TEMPLATE PRÊT À L'EMPLOI ===\n\n";

echo <<<'TEMPLATE'
// Copiez ce code dans vos scripts :

$start = hrtime(true);

// ===== VOTRE CODE ICI =====



// ===== FIN DE VOTRE CODE =====

$temps = (hrtime(true) - $start) / 1_000_000_000;
echo "Temps d'exécution : " . round($temps, 4) . " s\n";

TEMPLATE;

?>

      Fonctions du code - Doc officielle PHP

   php.net  
Description
Versions PHP
    array
Crée un tableau
PHP 4, 5, 7 et 8
    array_map
Applique une fonction sur les éléments d'un tableau
PHP 4, 5, 7 et 8
    count
Compte tous les éléments d'un tableau ou dans un objet Countable
PHP 4, 5, 7 et 8
    echo
Affiche une chaîne de caractères
PHP 4, 5, 7 et 8
    floor
Arrondit à l'entier inférieur
PHP 4, 5, 7 et 8
    isset
Détermine si une variable est déclarée et est différente de null
PHP 4, 5, 7 et 8
    microtime
Retourne le timestamp UNIX actuel avec les microsecondes
PHP 4, 5, 7 et 8
    printf
Affiche une chaîne de caractères formatée
PHP 4, 5, 7 et 8
    range
Crée un tableau contenant un intervalle d'éléments
PHP 4, 5, 7 et 8
    return
Retourne le controle du programme au module appelant
PHP 4, 5, 7 et 8
    round
Arrondit un nombre à virgule flottante
PHP 4, 5, 7 et 8
    shuffle
Mélange les éléments d'un tableau
PHP 4, 5, 7 et 8
    sleep
Arrête l'exécution durant quelques secondes
PHP 4, 5, 7 et 8
    sort
Trie un tableau en ordre croissant
PHP 4, 5, 7 et 8
    sprintf
Retourne une chaîne formatée
PHP 4, 5, 7 et 8
    sqrt
Racine carrée
PHP 4, 5, 7 et 8
    str_repeat
Répète une chaîne
PHP 4, 5, 7 et 8
    unset
Détruit une variable
PHP 4, 5, 7 et 8
    usleep
Arrête l'exécution durant quelques microsecondes
PHP 4, 5, 7 et 8

[1]

  • avatar

    Fabien

    31 Déc 2005 à 12:16

    Ce script est simple mais efficace.
    Merci à l'auteur, je vais l'utilisé pour mon TPE.
    Je n'oublie pas de le cité bien sure.

Minimum 10 mots. Votre commentaire sera visible après validation.


 Autres snippets qui pourraient vous intéresser

Initialise le temps d'exécution d'un script php

Compatibilité : PHP 5, PHP 7, PHP 8

2 tests pour apprendre comment utiliser la fonction set_time_limit () et réinitialiser le temps d'exécution d'une partie d'un code.

Calculer le temps d'exécution d'1 page web

Compatibilité : PHP 5, PHP 7, PHP 8

Calculer le temps d'exécution d'1 page web.

* Requêtes exécutées avec Recherche Contextuelle

  Les derniers scripts

PHP 8.5.5

logo PHP
Langue langue us
Date 12 Avril
Taille 32 Mo
Catégorie PHP

PHP 8.4.20

logo PHP
Langue langue us
Date 12 Avril
Taille 30 Mo
Catégorie PHP

Serendipity 2.6.0

logo Serendipity
Langue langue fr
Date 11 Avril
Taille 15 Mo
Catégorie Blogs

Drupal 11.3.6

logo Drupal
Langue langue us
Date 11 Avril
Taille 34 Mo
Catégorie CMS

TYPO3 14.2.0

logo TYPO3
Langue langue fr
Date 10 Avril
Taille 38 Mo
Catégorie CMS

Dolibarr ERP 23.0.1

logo Dolibarr ERP
Langue langue fr
Date 09 Avril
Taille 89 Mo
Catégorie Logiciels
avatar

Eric Potvin

  23 Sept 2005

  SOURCE   Télécharger

Information sur les mises à jour

Dernière mise à jour :

24 Août 2019
fonctionnement du code vérifié

15 Fév 2026
refactoring du code en PHP 8

18 264 Vues
Compatibilité du code
PHP 8