PHP Classes

File: tests/benchmarks/hashdos.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   iaso PHP JSON Parser Library   tests/benchmarks/hashdos.php   Download  
File: tests/benchmarks/hashdos.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: iaso PHP JSON Parser Library
Parse JSON strings immune to hash-DoS attacks
Author: By
Last change:
Date: 2 years ago
Size: 704 bytes
 

Contents

Class file image Download
<?php

use ParagonIE\Iaso\JSON;
require
'../../vendor/autoload.php';

/*
 * 26 MB PoC file
if (!file_exists('1048576.json')) {
    \shell_exec("wget https://raw.githubusercontent.com/bk2204/php-hash-dos/master/example/1048576.json");
}
$string = \file_get_contents('poc.json');
*/
$string = \file_get_contents('poc.json');

// Init variables.
$start = $end = 0.00;

$start = \microtime(true);
$native = \json_decode($string);
$end = \microtime(true);

$diff = $end - $start;
echo
number_format($diff, 3) . ' seconds (native)', PHP_EOL;

$start = \microtime(true);
$native = JSON::parse($string);
$end = \microtime(true);

$diff = $end - $start;
echo
number_format($diff, 3) . ' seconds (Iaso)', PHP_EOL;