V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Livid
V2EX  ›  PHP

用 Rust 实现 PHP Extension

  •  
  •   Livid · 2015-04-05 21:23:02 +08:00 · 3277 次点击
    这是一个创建于 3308 天前的主题,其中的信息可能已经有所发展或是发生改变。
    5 条回复    2015-04-16 08:50:04 +08:00
    kn007
        1
    kn007  
       2015-04-05 21:24:35 +08:00
    mark
    megoo
        2
    megoo  
       2015-04-06 01:27:39 +08:00
    现在用rust的人不多吧?楼主在学Rust?
    xwsoul
        3
    xwsoul  
       2015-04-06 11:21:57 +08:00
    酷炫...
    如果用 zephir 好像更容易一些

    zephir 代码
    `
    namespace Demo;

    class Fun {

    public static function fib(int at) {
    if (at == 0 || at == 1) {
    return at;
    } else {
    int i;
    long total = 1, par = 1, gp = 0;
    for i in range(1, at) {
    let total = par + gp;
    let gp = par;
    let par = total;
    }
    return total;
    }
    }

    }
    `

    原生PHP fib如题主链接中的代码:

    time php origin.php

    real 0m0.639s
    user 0m0.582s
    sys 0m0.052s

    zephir 编写的 php 代码

    `
    <?php
    //ext.php
    use Demo\Fun;

    for ($i = 0; $i < 100000; $i ++) {
    Fun::fib(92);
    }
    `

    执行效果:
    time php ext.php

    real 0m0.043s
    user 0m0.031s
    sys 0m0.011s
    jamlee
        4
    jamlee  
       2015-04-06 20:04:26 +08:00
    cpp-php这个也可以实现php的扩展,并且比较简单呢!
    crabRunning
        5
    crabRunning  
       2015-04-16 08:50:04 +08:00
    我的天,竟然是大Livid,这是python转php的节奏么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4188 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:11 · PVG 12:11 · LAX 21:11 · JFK 00:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.