#10 楼 @ShiningRay 只填最后一级就好了啊,别的都能从配置里查出来的啊
#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).
#2 楼 @ShiningRay 反正数据量小啊,不用数据库也可以嘛
直接硬编码到配置文件吧...
#22 楼 @blacktulip Google Maps 上找到了
#19 楼 @blacktulip 目测不是 UK 本土啊
#11 楼 @goinaction 没仔细用过 CloudFoundry ... 反正 Openshift 的 DIY 挺方便的,就一直折腾 OpenShift 了
地点?
人好多啊
没看见有要求 Chinese speaker?
税前 英镑 35K-43K 一年
#6 楼 @goinaction 一开始 CloudFoundry 只能用它支持的语言,即便现在也是要通过自定义 buildpack 的方式,OpenShift 很早就有 DIY 类型啊
我喜欢 OpenShift 咋办...
Emacs 挺好的啊,Erlang 官方就只提供 emacs mode
同求配色公式 ...
{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.
代码分别抄自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 最快
#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))
我贴的那个是 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 多一条指令...
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% )