Skip to content
This repository has been archived by the owner on Oct 18, 2019. It is now read-only.

php single thead implementation #12

Merged
merged 1 commit into from Sep 2, 2015
Merged

php single thead implementation #12

merged 1 commit into from Sep 2, 2015

Conversation

pqr
Copy link
Contributor

@pqr pqr commented May 15, 2015

requires php 5.4+

My machine (ssd, 16Gb, i7 haswell) results compared to golang:
golang 1.4 with -strategy=substring: 43,02s user 1,09s system 608% cpu 7,254 total
golang 1.4 with -strategy=regex: 168,96s user 0,75s system 736% cpu 23,039 total
php 5.6: 10,85s user 0,14s system 99% cpu 11,003 total

One sigle PHP thead works as good as golang 6 gorutines!

@FractalizeR
Copy link

That's really great ;) What about PHP7? It should be more or less stable for testing such things, I think.

fwrite($fh, $hood);
fwrite($fh, "\t");
fwrite($fh, $count);
fwrite($fh, "\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use 4th write operation instead 1?

@bobrik
Copy link

bobrik commented May 30, 2015

Just to make it clear: stripos only works for ascii, in golang it works on unicode. ToLower is slow in go indeed.

Go version can be optimized by using []byte instead of string to make GC happier, plus:

func toLower(b []byte) {
    for i, c := range b {
        if c >= 'A' && c <= 'Z' { b[i] += 'a' - 'A' }
    }
}

Results (php, go with 1 thread, go with 2 threads):

root@8e7d09e496e7:/home/bobrik/etl-language-comparison# ./run_php && ./run_php && ./run_php
13.301
12.558
12.506
root@8e7d09e496e7:/home/bobrik/etl-language-comparison# ./run_go && ./run_go && ./run_go
11.265
10.970
10.977
root@8e7d09e496e7:/home/bobrik/etl-language-comparison# ./run_go && ./run_go && ./run_go
5.691
5.645
5.676

It won't be fair, you know:

root@8e7d09e496e7:/home/bobrik/etl-language-comparison# time fgrep -ri knicks tmp/tweets > /dev/null
1.828

dimroc added a commit that referenced this pull request Sep 2, 2015
php single thead implementation
@dimroc dimroc merged commit b2dc979 into dimroc:master Sep 2, 2015
@dimroc
Copy link
Owner

dimroc commented Nov 16, 2015

Hi @pqr et al,
It would be great to capture details of the implementation in a README.md in the php/ folder. @pqr , @bobrik are you up to the task? It shouldn't take long.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants