PHP turi iconv ir mb_convert_encoding funkcijas, kurios daro tą patį – perkoduoja simbolių eilutę.

Prabenchmarkinus man tas funkcijas ant dviejų sistemų (win ir linux) jų vykdymo greitis panašus, tačiau iconv, 5 – 15% greitesnė. Benchmarko kodas:

<?php

$string = 'labas, kas pas jus yra gero? Ąžuolų turite?';
$loop_count = 100;

require_once('Benchmark-1.2.6/Profiler.php');

$profiler = new Benchmark_Profiler();
$profiler->start();

$profiler->enterSection('mb_convert_encoding');
for ($i = 0; $i < $loop_count; $i++) {
    $result = mb_convert_encoding($data, 'UTF-8', 'ISO-8859-13'); // windows-1257 to utf-8
}

$profiler->leaveSection('mb_convert_encoding');

$profiler->enterSection('iconv');
for ($i = 0; $i < $loop_count; $i++) {
    $result = iconv('ISO-8859-13', 'UTF-8', $data);
}
$profiler->leaveSection('iconv');

$profiler->stop();
$profiler->display();

?>

One Response to “iconv ir mb_convert_encoding”

  1. enc Says:

    kode prie mb_convert_string() f-jos komentaras blogas. turėtų būti ne windows-1257 (kas f-joje rašoma kaip CP1257), o Baltic (ISO) .)


Leave a Reply