discussion:-how-come-php-seems-so-much-faster-than-rust?

Hi everyone,

I’ve been working on a script that can read in Apache logs over standard input, and then extract information such as the user agent, the request method, etc. It’s a PHP script and I’ve been thinking about making a super fast Rust version.

Surprisingly, however, I seem to be finding that PHP is much much faster than Rust. As a PHP developer I am not surprised that PHP is fast per se, but I would expect it to be slower than Rust, because PHP needs to parse, interpret, compile and run the code, whereas in Rust it’s all precompiled, pre-optimized native code.

Can someone shed some light as to why my Rust program is so slow? I’ve taken the code and boiled it down to a pair of simple examples. I’m not using the captures in the Rust file, but I will be needing them in the final script so is_match would be a big performance improvement but is not an option here.

Here’s how I test the difference. I’m using PHP 7.3 and a log file of 64,000 lines:

cargo build --release; hyperfine 'target/release/apache-log-parser < test.log' # 185ms
hyperfine 'php example.php < test.log' # 84 ms

Rust:

extern crate regex;

use std::io;
use std::io::prelude::*;
use regex::Regex;

fn main() -> io::Result<()> {
    let regex = r#"^([^ ] ) ([^ ] ) ([^[] )  [([^]]*)] "([A-Z] ) ([^"]*)" ([0-9] ) ([0-9] ) "([^"]*)" "([^"]*)"$"#;
    let regex = Regex::new(regex).unwrap();

    for line in std::io::stdin().lock().lines() {
        let line = line.unwrap();
        if let Some(_) = regex.captures(&line) {
            println!("{}", line);
        }
    }
    Ok(())
}

PHP:

discussion:-9-years-ago-sketch-took-the-torch-from-adobe-fireworks,-but…

I’m shocked how quickly Figma was able to overshadow Sketch in every single way that matters for professional collaborative design…

No more Zeplin for comments which means less team confusion, no new workflows, and one less license

A robust prototype system that gives you triggers such as hover that WE ALL NEED, while still keeping the workflows lean and intuitive

More intuitive symbol editing and management

Heirarchal file and project management

Web based UI

Honest pricing model, none of this sudden subscription service BS. It’s a subscription from the start, or not. F U

People other than designers like Figma….unlike Sketch, which I can’t explain, but getting coworkers to covert to Figma was a dream, whereas the only people that I Kno that like sketch are designers. No clue, but it’s real.

I love you and I will miss you, but I’m never coming back. Too slow to answer the needs of designers and way too much emphasis on bug fixes and brand.