PHP runtimeRuntime report7 repeated rounds

Parsing timestamp strings with strtotime and DateTimeImmutable

A repeated parsing baseline for two common PHP date APIs using explicit UTC strings.

Runtime investigation

Question and test setup

What timing difference appears when the same explicit timestamp strings are parsed with strtotime or DateTimeImmutable?

Initial expectation

strtotime may have lower object-allocation overhead, while DateTimeImmutable provides a richer and often safer interface for later date operations.

Date code fails more often from ambiguous input and timezone assumptions than from parser speed. This report keeps the input explicit so it can isolate API overhead.

An immutable object can reduce accidental mutation in business logic even when construction costs more.

The measured gap

Lowest measured medianstrtotime
Median time880.15 µs
Median spread15.69%

What this run shows: strtotime parsed the fixed timestamp fixture faster; timezone handling, error behavior and API clarity remain more important than the isolated gap. The slowest-to-fastest median spread was 15.69% on the measured host.

Measured results. Lower median time is faster.
VariantMedianMiddle 50%Operations/sAdditional measure
strtotimeFastest880.15 µs873.59 µs–884.42 µs1,136
DateTimeImmutable1.02 ms1.02 ms–1.05 ms982

What the numbers suggest

The measured gap should not override correctness. Explicit formats, validation and timezone handling are the first design concerns.

Use scalar timestamps in a tightly profiled ingestion path when that representation is sufficient. Use immutable date objects when downstream operations benefit from their semantics and API.

When the difference is worth acting on

  • Reject ambiguous external date strings instead of relying on permissive parsing.
  • Carry an explicit timezone at system boundaries.
  • Profile full date-processing workflows, not construction alone.

Repetition and environment

  1. The fixture contains 1,200 valid timestamp strings with an explicit UTC designator.
  2. Each variant parses every string and folds timestamps into a checksum.
  3. Formatting, timezone conversion and interval arithmetic are not included.
20operations/sample
7measured rounds
2variants
Medianprimary statistic
Open measured environment
Measurement run
2026-07-22T15:23:56+00:00
PHP
8.4.23 (cli)
Operating system
Linux 4.18.0-553.85.1.el8_10.x86_64
Architecture
x86_64
Processor
AMD EPYC-Rome Processor
Reported host memory
15.02 GiB host total
CLI OPcache
0
PHP memory limit
1024M
Loaded study extensions
json, openssl, zlib, mbstring, pdo_sqlite
Timing clock
hrtime(true)
Measured rounds
7

Reasons the ranking may move

  • Only valid, explicit UTC strings are tested.
  • The study does not compare createFromFormat or invalid-input handling.

Primary documentation

These sources describe the PHP functions under test. The performance ranking comes only from this published fixture and environment.

Challenge the local result