Skip to content

Instantly share code, notes, and snippets.

@arnaud-lb
Created January 22, 2024 13:45
Show Gist options
  • Save arnaud-lb/ef1ef37d3c981015b722089b7652bff5 to your computer and use it in GitHub Desktop.
Save arnaud-lb/ef1ef37d3c981015b722089b7652bff5 to your computer and use it in GitHub Desktop.
<?php
require 'DateTimeMap.php';
for ($i = 0; $i < 100; $i++) {
$map = new DateTimeMap();
for ($j = 0; $j < 100; $j++) {
$map->set($j, new DateTime());
$map->get($j);
}
}
<?php
require 'GenericMap.php';
for ($i = 0; $i < 100; $i++) {
$map = new GenericMap<DateTime>();
for ($j = 0; $j < 100; $j++) {
$map->set($j, new DateTime());
$map->get($j);
}
}
<?php
require 'UntypedMap.php';
for ($i = 0; $i < 100; $i++) {
$map = new UntypedMap();
for ($j = 0; $j < 100; $j++) {
$map->set($j, new DateTime());
$map->get($j);
}
}
<?php
use DateTime;
final class DateTimeMap
{
private array $elems;
public function __construct()
{
$this->elems = [];
}
public function get(string $key): DateTime
{
return $this->elems[$key];
}
public function set(string $key, DateTime $value): void
{
$this->elems[$key] = $value;
}
}
<?php
final class GenericMap<T>
{
private array $elems;
public function __construct()
{
$this->elems = [];
}
public function get(string $key): T
{
return $this->elems[$key];
}
public function set(string $key, T $value): void
{
$this->elems[$key] = $value;
}
}
<?php
final class UntypedMap
{
private array $elems;
public function __construct()
{
$this->elems = [];
}
public function get(string $key)
{
return $this->elems[$key];
}
public function set(string $key, $value): void
{
$this->elems[$key] = $value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment