note 128379 added to intldateformatter.formatobject

From: Date: Sat, 08 Apr 2023 10:12:25 +0000
Subject: note 128379 added to intldateformatter.formatobject
Groups: php.notes 
Request: Send a blank email to php-notes+get-220334@lists.php.net to get a copy of this message
format vs static formatObject ** The formatObject is NOT slower! (on PHP 5.5) ** Use either the format method or the static formatObject. Since formatObject is doing the work of new IntlDateFormatter with the provided pattern, the instantiation line must be included in the loop! Another debunked flawed false test! php -v PHP 5.5.26-1+deb.sury.org~precise+1 (cli) (built: Jun 15 2015 10:04:01) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans <?php date_default_timezone_set('America/Los_Angeles'); $n = 3000; $dt = new DateTime('2015-01-03 12:32:44'); $time[] = microtime(true); for($i=0;$i<$n;$i++) { $a = IntlDateFormatter::formatObject($dt, 'MMMM dd', 'hu_HU'); } echo "$a\n"; $time[] = microtime(true); for($i=0;$i<$n;$i++) { $df = new IntlDateFormatter('hu_HU', IntlDateFormatter::SHORT, IntlDateFormatter::NONE, null, null, 'MMMM dd'); $a = $df->format($dt); } echo "$a\n"; $time[] = microtime(true); for($j=1;$j<count($time);$j++) { printf("%fs\n", $time[$j]-$time[$j-1]); } ?> formatObject : 0.336579s format : 0.391158s ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 2604:3d08:5e7b:8850:2c93:cd22:38e4:3d2) ---- Manual Page -- https://php.net/manual/en/intldateformatter.formatobject.php Edit -- https://main.php.net/note/edit/128379 Del: integrated -- https://main.php.net/note/delete/128379/integrated Del: useless -- https://main.php.net/note/delete/128379/useless Del: bad code -- https://main.php.net/note/delete/128379/bad+code Del: spam -- https://main.php.net/note/delete/128379/spam Del: non-english -- https://main.php.net/note/delete/128379/non-english Del: in docs -- https://main.php.net/note/delete/128379/in+docs Del: other reasons-- https://main.php.net/note/delete/128379 Reject -- https://main.php.net/note/reject/128379 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220334) next »