废话不多说上图

这是代码:

   $microtime = microtime(true);
    $num = 0;
    for ($i = 0; $i < 10000; $i++) {
        for ($j = 0; $j < 1000; $j++) {
            for ($k = 0; $k < 100; $k++) {
                $num = $num - $k + $i + $j;
            }

        }
    }

    echo "num:{$num}\n";
    var_dump(microtime(true) - $microtime);

这是测试:
上面是未开,下面是开启了jit

image.png

对比差距还是很明显的,来对比其他语言的速度

rust

代码:

fn execute_function() {
    let mut num:i64 = 0;
    for i in 0..10000 {
        for j in 0..1000 {
            for k in 0..100 {
                num = num- k + i + j ;
            }
        }
    }
    println!("{}", num)
}

结果:
775722f5a86454ff1b50fd39705e7aa.png

C

#include <stdio.h>
#include <time.h>

void execute_function() {
    long long num = 0;
    for (int i = 0; i < 10000; i++) {
        for (int j = 0; j < 1000; j++) {
            for (int k = 0; k < 100; k++) {
                num = num  + i + j - k;
            }
        }

    }
    printf("%lld\n",num);
}

int main() {
    clock_t start, end;

    start = clock();
    execute_function();
    end = clock();

    double time_taken = ((double) (end - start)) / CLOCKS_PER_SEC; // in seconds

    printf("Time taken for function to execute: %f\n", time_taken);

    return 0;
}

结果:
efaf9b50070c72b70386a60675480fe.png

结论:虽然php运行在docker中进行的测试,测试结果与rust和c直接跑在windows上肯定是有些区别的,但是jit开启对密集运算的提升还是非常明显,也算略微弥补了php密集运算的不足。


vanve
27 声望2 粉丝