my php port of some js code is 24x as slow as the js code itself

This page summarizes the projects mentioned and recommended in the original post on /r/PHP

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • buffer

    PHP extension for buffer based typed arrays (by nikic)

  • Did you try this: https://github.com/nikic/buffer ?? But I don't think your code does the same thing between PHP and JS. If you count the number of times your `F` gets called, php does it 4mill times and JS does it 16mill times. Also, bit operations SHOULD be faster in PHP than in JS (php stores int and js stores floats last time i checked), BUT if you pass a large array by reference to a method/function, and you change it, then it will copy that array... so it will be slow. I see that in JS you do: ``` for (var i = 1; i < 16; i += 2) { x[1] ^= F(S, x8, 0) ^ P[i]; x[0] ^= F(S, x8, 4) ^ P[i+1]; } ``` But in PHP you use x[1] to calculate x[0] ``` for ($i = 1; $i < 16; $i += 2) { $x[1] ^= F($x[0]) ^ $p[$i]; $x[0] ^= F($x[1]) ^ $p[$i + 1]; } ``` So i'm pretty sure your not actually doing the same math here. In the past, I have used this implementation for reference for the blowfish algorithm (javascript to php communication) https://github.com/themattharris/PHP-Blowfish/blob/master/blowfish.php It may give you some ideas. (tried to look it up, but my brain is not into bit operations right now lol)

  • node-bcrypt-pbkdf

    Port of the OpenBSD `bcrypt_pbkdf` function to pure Javascript

  • I was trying to port https://github.com/TritonDataCenter/node-bcrypt-pbkdf from JS to PHP but my port is significantly slower than the JS code and it's not clear to me what, if anything, I can do to speed it up.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • PHP-Blowfish

    Discontinued Blowfish encryption class entirely in PHP

  • Did you try this: https://github.com/nikic/buffer ?? But I don't think your code does the same thing between PHP and JS. If you count the number of times your `F` gets called, php does it 4mill times and JS does it 16mill times. Also, bit operations SHOULD be faster in PHP than in JS (php stores int and js stores floats last time i checked), BUT if you pass a large array by reference to a method/function, and you change it, then it will copy that array... so it will be slow. I see that in JS you do: ``` for (var i = 1; i < 16; i += 2) { x[1] ^= F(S, x8, 0) ^ P[i]; x[0] ^= F(S, x8, 4) ^ P[i+1]; } ``` But in PHP you use x[1] to calculate x[0] ``` for ($i = 1; $i < 16; $i += 2) { $x[1] ^= F($x[0]) ^ $p[$i]; $x[0] ^= F($x[1]) ^ $p[$i + 1]; } ``` So i'm pretty sure your not actually doing the same math here. In the past, I have used this implementation for reference for the blowfish algorithm (javascript to php communication) https://github.com/themattharris/PHP-Blowfish/blob/master/blowfish.php It may give you some ideas. (tried to look it up, but my brain is not into bit operations right now lol)

  • Zephir

    Zephir is a compiled high-level language aimed to ease the creation of C-extensions for PHP

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts