Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
bhuztez
@bhuztez
VIP
NO. 1569 / 2012-03-24

40 Topics / 2614 Replies
105 Followers
0 Following
0 Favorites
No GitHub.
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 咨询一下这个怎么建模 at July 25, 2013

    #12 楼 @fenprace 纯 Prolog 的语义左递归就死循环了。当然这里没用到也没这个问题。所以现在不得不去看 datalog 语义是怎么实现的

  • [欧洲] Chinese speaker Ruby/JS/Web Developer - 招聘已结束 at July 25, 2013

    #36 楼 @Peter 全靠目测...

  • 咨询一下这个怎么建模 at July 25, 2013

    #10 楼 @ShiningRay 只填最后一级就好了啊,别的都能从配置里查出来的啊

  • 咨询一下这个怎么建模 at July 24, 2013

    #5 楼 @ShiningRay 数量小,而且基本不会变的数据,没必要用数据库吧。直接从配置文件中载入就够了啊。

    state_of_county("Monroe", "New York").
    state_of_county("Suffolk", "Massachusetts").
    county_of_city("Rochester", "Monroe").
    county_of_city("Boston", "Suffolk").
    
    state_of_city(City, State) :-
      state_of_county(County, State),
      county_of_city(City, County).
    
  • 咨询一下这个怎么建模 at July 24, 2013

    #2 楼 @ShiningRay 反正数据量小啊,不用数据库也可以嘛

  • 咨询一下这个怎么建模 at July 24, 2013

    直接硬编码到配置文件吧...

  • [欧洲] Chinese speaker Ruby/JS/Web Developer - 招聘已结束 at July 24, 2013

    #22 楼 @blacktulip Google Maps 上找到了

    http://goo.gl/maps/njBhx

  • [欧洲] Chinese speaker Ruby/JS/Web Developer - 招聘已结束 at July 24, 2013

    #19 楼 @blacktulip 目测不是 UK 本土啊

  • 求推荐颜色或计算公式 at July 24, 2013

    #17 楼 @chairy11 apt-get install ...

  • 开源的 Open Source PaaS,Flynn,正在从社区筹募资金。号称小 Heroku. at July 24, 2013

    #11 楼 @goinaction 没仔细用过 CloudFoundry ... 反正 Openshift 的 DIY 挺方便的,就一直折腾 OpenShift 了

  • 求推荐颜色或计算公式 at July 24, 2013

    #15 楼 @chairy11

    可以试试

    gpick

    https://code.google.com/p/gpick/

    KColorEdit

    http://extragear.kde.org/apps/kcoloredit/

  • [欧洲] Chinese speaker Ruby/JS/Web Developer - 招聘已结束 at July 24, 2013

    地点?

  • [上海] "英语流利说"诚聘 Rails 开发工程师 at July 24, 2013

    人好多啊

  • [欧洲] Chinese speaker Ruby/JS/Web Developer - 招聘已结束 at July 24, 2013

    没看见有要求 Chinese speaker?

    税前 英镑 35K-43K 一年

  • 开源的 Open Source PaaS,Flynn,正在从社区筹募资金。号称小 Heroku. at July 24, 2013

    #6 楼 @goinaction 一开始 CloudFoundry 只能用它支持的语言,即便现在也是要通过自定义 buildpack 的方式,OpenShift 很早就有 DIY 类型啊

  • 开源的 Open Source PaaS,Flynn,正在从社区筹募资金。号称小 Heroku. at July 24, 2013

    我喜欢 OpenShift 咋办...

  • 制作 Slides 的错误示范 at July 24, 2013

    Emacs 挺好的啊,Erlang 官方就只提供 emacs mode

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 24, 2013

    #45 楼 @luikore 不是寄存器机的语义啊,我说的是 lua 函数调用的语义啊 ...

  • 求推荐颜色或计算公式 at July 24, 2013

    #8 楼 @nightire 求能排除不合理搭配的公式...

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 24, 2013

    #43 楼 @luikore 语义上函数调用和返回都是栈啊

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 24, 2013

    #41 楼 @luikore lua 虽然是栈,就是基本不做 push/pop 的

    Python 和 Ruby 通常情况都是相当于是每个函数独立分别固定大小的内存作为栈的,和寄存器机并没有显著区别。

  • 求推荐颜色或计算公式 at July 24, 2013

    同求配色公式 ...

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 24, 2013

    #39 楼 @luikore

    {function, fib, 1, 2}.
      {label,1}.
        {line,[{location,"fib.erl",5}]}.
        {func_info,{atom,fib},{atom,fib},1}.
      {label,2}.
        {test,is_integer,{f,4},[{x,0}]}.
        {select_val,{x,0},{f,4},{list,[{integer,1},{f,3},{integer,0},{f,3}]}}.
      {label,3}.
        {move,{integer,1},{x,0}}.
        return.
      {label,4}.
        {allocate_zero,1,1}.
        {line,[{location,"fib.erl",10}]}.
        {gc_bif,'-',{f,0},1,[{x,0},{integer,1}],{x,1}}.
        {move,{x,0},{y,0}}.
        {move,{x,1},{x,0}}.
        {line,[{location,"fib.erl",10}]}.
        {call,1,{f,2}}.
        {line,[{location,"fib.erl",10}]}.
        {gc_bif,'-',{f,0},1,[{y,0},{integer,2}],{x,1}}.
        {move,{x,0},{y,0}}.
        {move,{x,1},{x,0}}.
        {line,[{location,"fib.erl",10}]}.
        {call,1,{f,2}}.
        {line,[{location,"fib.erl",10}]}.
        {gc_bif,'+',{f,0},1,[{y,0},{x,0}],{x,0}}.
        {deallocate,1}.
        return.
    
  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 24, 2013

    #34 楼 @luikore 现在是为了比较速度啊,明显运行速度越慢越容易比出来啊,运行速度太快,误差都比运行时间长就坑爹了。

    JavaScript 开了 JIT 才比 Erlang 快没多少,这怎么解释... Pypy 开了 JIT 还不如 Erlang

    Ruby 的字节码和 Python 几乎完全一样,但是速度确比 Python 快了一倍,都赶上 lua 了,这怎么解释。

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 23, 2013

    #27 楼 @luikore

    代码分别抄自http://rosettacode.org/wiki/Fibonacci_sequence

    AWK SWIProlog 和 Python 差不多

    Perl 更慢... Tcl 和 Perl 差不多

    bc 比 Perl 还慢

    目前 Octave 垫底

    lua 比 Ruby 快那么点

    boo 和 Erlang 差不多

    Mozilla 的 JS 参数选对了比 Erlang 快,当然了是开了 JIT, 参数js -b -m fib.js比 Erlang 快,参数js -b -j fib.js只能和 Ruby 比比

    目前试过的里面纯解释还是 Erlang 最快

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 23, 2013

    #30 楼 @luikore 根据定义,所有函数最后都会自动加上这个...

    我数的是实际会用到的指令。

    刚才我妄图把那两个指令删了,好像把 Python 解释器搞挂了...

    可以先用我的 orz 生成一下 bytecode http://xiazheteng.github.io/orz/

    from orz.lua.asm import Assembly, Label
    
    from orz.asm import Opcode, StringTable
    from orz.symbol import Global, Local, Name, Attribute, calculate_slots
    
    import StringIO
    import marshal
    
    
    def compile_fib(parent, stringtable):
        filename = Name(__file__)
        func_name = Name("fib")
    
        n = Local("n")
        fib = Global("fib")
    
        nnames = calculate_slots([n, fib])
    
        asm = Assembly(
            func_name, *nnames,
            argcount = 1,
            parent = parent)
    
        asm.set_lineno(1)
    
        asm.emit(Opcode.LOAD_FAST, n.slot)
        asm.load_const(2)
        asm.emit(Opcode.COMPARE_OP, 0)
    
        l = Label()
    
        asm.emit(Opcode.POP_JUMP_IF_FALSE, l)
    
        asm.load_const(1)
        asm.emit(Opcode.RETURN_VALUE)
    
        asm.emit(Opcode.LABEL, l)
    
        asm.emit(Opcode.LOAD_GLOBAL, fib.slot)
        asm.emit(Opcode.LOAD_FAST, n.slot)
        asm.load_const(2)
        asm.emit(Opcode.BINARY_SUBTRACT)
        asm.emit(Opcode.CALL_FUNCTION, 1)
    
        asm.emit(Opcode.LOAD_GLOBAL, fib.slot)
        asm.emit(Opcode.LOAD_FAST, n.slot)
        asm.load_const(1)
        asm.emit(Opcode.BINARY_SUBTRACT)
        asm.emit(Opcode.CALL_FUNCTION, 1)
    
        asm.emit(Opcode.BINARY_ADD)
        asm.emit(Opcode.RETURN_VALUE)
    
        # asm.load_const(None)
        # asm.emit(Opcode.RETURN_VALUE)
    
        for names in nnames:
            for name in names:
                name.s = stringtable.add(name.name, interned=True)
    
        func_name.s = stringtable.add(func_name.name, interned=True)
    
        return asm
    
    
    def compile_mod():
        stringtable = StringTable()
    
        filename = Name(__file__)
        fname = Name(__name__)
    
        fib = Global("fib")
    
        nnames = calculate_slots([fib])
    
        asm = Assembly(fname, *nnames)
        asm.set_lineno(1)
    
        asm.load_const(compile_fib(asm, stringtable))
        asm.emit(Opcode.MAKE_FUNCTION, 0)
        asm.emit(Opcode.STORE_GLOBAL, fib.slot)
        asm.load_const(None)
        asm.emit(Opcode.RETURN_VALUE)
    
        for names in nnames:
            for name in names:
                name.s = stringtable.add(name.name, interned=True)
    
        fname.s = stringtable.add(fname.name, interned=True)
    
        stringtable.close()
    
        buf = StringIO.StringIO()
        asm.serialize(buf, __file__)
        return marshal.loads(buf.getvalue())
    
    
    mod = compile_mod()
    d = {}
    exec mod in d
    fib = d['fib']
    
    if __name__=='__main__':
        from timeit import Timer
        t = Timer("print(fib(35))","from __main__ import fib")
        print(t.timeit(1))
    
  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 23, 2013

    #27 楼 @luikore 不是无值,是 POP_JUMP 顺便 POP 掉了...

    erlang 也是纯解释执行啊

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 23, 2013

    #24 楼 @luikore

    Erlang,快得离谱啊,竟然连 1 秒都不要...

    -module(fib).
    
    -export([test/0, fib/1]).
    
    fib(0) ->
        1;
    fib(1) ->
        1;
    fib(N) ->
        fib(N-1)+fib(N-2).
    
    test() ->
        {T, V} = timer:tc(fib, fib, [35]),
        io:format("~w:~w~n", [T,V]).
    
  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 23, 2013

    #23 楼 @luikore

    我贴的那个是 Python2

    3 开了 2 没开,2 还比 3 快不少 ... 不科学啊

    http://bugs.python.org/issue4753

    肯定是 Ruby 用了黑魔法...

    Python

    def fib(n):
        if n < 2:
            return 1
        else:
            return fib(n - 1) + fib(n - 2)
    
    2           0 LOAD_FAST                0 (n)
                3 LOAD_CONST               1 (2)
                6 COMPARE_OP               0 (<)
                9 POP_JUMP_IF_FALSE       16
    
    3          12 LOAD_CONST               2 (1)
               15 RETURN_VALUE        
    
    5     >>   16 LOAD_GLOBAL              0 (fib)
               19 LOAD_FAST                0 (n)
               22 LOAD_CONST               2 (1)
               25 BINARY_SUBTRACT     
               26 CALL_FUNCTION            1
               29 LOAD_GLOBAL              0 (fib)
               32 LOAD_FAST                0 (n)
               35 LOAD_CONST               1 (2)
               38 BINARY_SUBTRACT     
               39 CALL_FUNCTION            1
               42 BINARY_ADD          
               43 RETURN_VALUE        
               44 LOAD_CONST               0 (None)
               47 RETURN_VALUE        
    
    def fib n
      if n < 2
        1
      else
        fib(n - 1) + fib(n - 2)
      end
    end
    
    local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1] s1)
    [ 2] n<Arg>     
    0000 getlocal         n                                               (   1)
    0002 putobject        2
    0004 opt_lt           <ic:6>
    0006 branchunless     12
    0008 putobject        1                                               (   2)
    0010 leave                                                            (   1)
    0011 pop              
    0012 putself                                                          (   4)
    0013 getlocal         n
    0015 putobject        1
    0017 opt_minus        <ic:7>
    0019 send             :fib, 1, nil, 8, <ic:2>
    0025 putself          
    0026 getlocal         n
    0028 putobject        2
    0030 opt_minus        <ic:8>
    0032 send             :fib, 1, nil, 8, <ic:4>
    0038 opt_plus         <ic:9>
    0040 leave            
    
    function fib(n)
      if (n<2) then
        return 1
      end
    
      return fib(n-1)+fib(n-2)
    end
    
    function <fib.lua:1,7> (13 instructions, 52 bytes at 0x1120710)
    1 param, 4 slots, 0 upvalues, 1 local, 3 constants, 0 functions
        1   [2] LT          0 0 -1  ; - 2
        2   [2] JMP         2   ; to 5
        3   [3] LOADK       1 -2    ; 1
        4   [3] RETURN      1 2
        5   [6] GETGLOBAL   1 -3    ; fib
        6   [6] SUB         2 0 -2  ; - 1
        7   [6] CALL        1 2 2
        8   [6] GETGLOBAL   2 -3    ; fib
        9   [6] SUB         3 0 -1  ; - 2
        10  [6] CALL        2 2 2
        11  [6] ADD         1 1 2
        12  [6] RETURN      1 2
        13  [7] RETURN      0 1
    

    还 Ruby 多一条指令...

  • [Benchmark] Ruby 2.0 真的快了不少,还是我的 Python 代码有问题? at July 23, 2013

    #17 楼 @luikore

    Python

    ==8232== I   refs:      24,435,810,159
    ==8232== I1  misses:           424,549
    ==8232== LLi misses:             7,356
    ==8232== I1  miss rate:           0.00%
    ==8232== LLi miss rate:           0.00%
    ==8232== 
    ==8232== D   refs:      11,447,475,486  (8,210,939,243 rd   + 3,236,536,243 wr)
    ==8232== D1  misses:           505,807  (      410,181 rd   +        95,626 wr)
    ==8232== LLd misses:            57,991  (       23,760 rd   +        34,231 wr)
    ==8232== D1  miss rate:            0.0% (          0.0%     +           0.0%  )
    ==8232== LLd miss rate:            0.0% (          0.0%     +           0.0%  )
    ==8232== 
    ==8232== LL refs:              930,356  (      834,730 rd   +        95,626 wr)
    ==8232== LL misses:             65,347  (       31,116 rd   +        34,231 wr)
    ==8232== LL miss rate:             0.0% (          0.0%     +           0.0%  )
    

    Ruby

    ==8464== I   refs:      14,783,720,041
    ==8464== I1  misses:           137,316
    ==8464== LLi misses:             9,038
    ==8464== I1  miss rate:           0.00%
    ==8464== LLi miss rate:           0.00%
    ==8464== 
    ==8464== D   refs:       6,208,884,291  (3,666,216,719 rd   + 2,542,667,572 wr)
    ==8464== D1  misses:           205,003  (      150,900 rd   +        54,103 wr)
    ==8464== LLd misses:            57,501  (       17,151 rd   +        40,350 wr)
    ==8464== D1  miss rate:            0.0% (          0.0%     +           0.0%  )
    ==8464== LLd miss rate:            0.0% (          0.0%     +           0.0%  )
    ==8464== 
    ==8464== LL refs:              342,319  (      288,216 rd   +        54,103 wr)
    ==8464== LL misses:             66,539  (       26,189 rd   +        40,350 wr)
    ==8464== LL miss rate:             0.0% (          0.0%     +           0.0%  )
    
  • Prev
  • 1
  • 2
  • …
  • 35
  • 36
  • 37
  • 38
  • 39
  • …
  • 84
  • 85
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English