in reply to Re^3: Why this code is so slow if run in thread?
in thread Why this code is so slow if run in thread?
You are right about "substr" being, unexpectedly, too slow with utf strings and threads. This program takes 12 seconds on my machine (I wanted some Greek letters, but it looks they are replaced with ugly codes. I think the idea is clear):
use utf8; use threads; threads-> create( sub { $s = 'αβγδ' x 1000_000; substr( $s, 0, 1000 ) for 1 .. 1000; })-> join; print time - $^T;
But then simple solution will be to, first, get a substring, and only then decode it. I.e. to move "decode" into loop. Then everything works as expected.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Why this code is so slow if run in thread?
by BrowserUk (Patriarch) on Dec 12, 2016 at 12:01 UTC | |
by vr (Curate) on Dec 12, 2016 at 12:11 UTC | |
by BrowserUk (Patriarch) on Dec 12, 2016 at 12:20 UTC | |
by vr (Curate) on Dec 12, 2016 at 12:27 UTC | |
by BrowserUk (Patriarch) on Dec 12, 2016 at 13:18 UTC | |
by BrowserUk (Patriarch) on Dec 14, 2016 at 01:18 UTC | |
|