Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alright, thanks for the input, I did "my homework" based on it and got the results, working with 50MB sample of actual CSV data:</p> <p>First, iterating over the file using PHP:</p> <pre><code>$in = fopen("a.txt", "r"); $out = fopen("p.txt", "w+"); $start = microtime(true); while(($line = fgets($in)) !== false) { $converted = iconv("UTF-8", "EUC-JP//TRANSLIT", $line); fwrite($out, $converted); } $elapsed = microtime(true) - $start; echo "&lt;br&gt;Iconv took $elapsed seconds\r\n"; </code></pre> <blockquote> <p><br>Iconv took 2.2817220687866 seconds</p> </blockquote> <p>That's not so bad I guess, so I tried the exact same approach in #bash, so it wouldn't have to load all the file but iterate over each line instead (which might not exactly happen as I understand what Lajos Veres answered). Indeed, this method wasn't exactly efficient (CPU was under a heavy load all the time). Also, the output file is smaller than the other 2, although after a quick look it looks the same, so I must have made a mistake in the bash script, however, that shouldn't have such effect on performance anyway:</p> <pre><code>#!/bin/bash echo "" &gt; b.txt time echo $( while read line do echo $line |iconv -f utf-8 -t EUC-JP//TRANSLIT &gt;&gt; b.txt done &lt; a.txt ) </code></pre> <blockquote> <p>real 9m40.535s user 2m2.191s sys 3m18.993s</p> </blockquote> <p>And then the classic approach which I would have expected to hog the memory, however, checking the CPU/Memory usage, it didn't seem to take any more memory than any other approach, therefore being a winner:</p> <pre><code>#!/bin/bash time echo $( iconv -f utf-8 -t EUC-JP//TRANSLIT a.txt -o b2.txt ) </code></pre> <blockquote> <p>real 0m0.256s user 0m0.195s sys 0m0.060s</p> </blockquote> <p>I'll try to get a bigger file sample to test the 2 more efficient methods to make sure the memory usage doesn't get significant, however, the result seems obvious enough to assume the single pass through the whole file in bash is the most efficient (I didn't try that in PHP, as I believe loading an entire file to an array/string in PHP isn't ever a good idea).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload