Break the rules (or need for speed #1)

Avatar von Pierre Joye

Sometimes some has to process a huge amount of data, applying stupid tests and formulas. There I was and stuck on low performance problem.

The obvious way is to implement the critical part (the stupid tests and formula in C and process the data using the C implementation only), sadly it’s often not even possible to customize php.

Having reached a point where no further optimizations were possible, I start to see what is slow inside php or what I can add to make trivial tasks faster.

One test surprised me: get the sign of a number.

So I go for a new get_sign() internal function and these results:

get_sign: 0.095184011459351
php tests: 0.21789693832397

No comment as I’m pretty sure such new functions will be rejected, keeping in mind the famous „1 line php code“ rule. What’s about (default) speed is my only anwser.

patch: http://pierre.dotgeek.org/ze2/get_sign.patch
tests: http://pierre.dotgeek.org/ze2/get_sign_test.phps

Avatar von Pierre Joye

Kommentare

2 Antworten zu „Break the rules (or need for speed #1)“

  1. Your benchmark results miss both the PHP code to benchmark it, and the number of iterations.

  2. As Pierre wrote before sometimes you need functions you usually would say "no, you’ll never need this, this task can be done with just one line PHP" but later you see "Okay, now I would need it".

    We hat such a situation a few day

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert


Für das Handling unseres Newsletters nutzen wir den Dienst HubSpot. Mehr Informationen, insbesondere auch zu Deinem Widerrufsrecht, kannst Du jederzeit unserer Datenschutzerklärung entnehmen.