| Thread overview | |||||
|---|---|---|---|---|---|
|
April 05, 2012 benchmark dict list and string, D vs python vs lua | ||||
|---|---|---|---|---|
| ||||
Hey, I wrote some code to benchmark dict list and string in D, python and lua. D is a great language, but some library look comparatively slow. Some where may be wrong, I start D just today. D test: code: http://pastebin.com/qF7N4wLx dict set: 2.251s dict get: 1.957s dict cleat: 0.00s list set: 0.085s list get: 0.007s list each: 0.014s str find: 1.254s str replace: 1.870s Python test: code: http://pastebin.com/m3qMjPcM dict set: 1.05s dict get: 0.75s dict cleat: 0.11s list set: 0.02s list get: 0.09s list each: 0.09s str find: 0.94s str replace: 0.67s Lua test: code: http://pastebin.com/TFTnsWzX dict set: 2.11s dict get: 0.87s dict cleat: 0.19s list set: 0.33s list get: 0.03s list each: 0.09s str find: 0.94s str replace: 1.10s Compare (> mean faster than): dict set: python > lua > D dict get: python > lua > D dict clear: D > lua > python list set: python > D > lua list get: D > lua > python list each: D > lua = python str find: python = lua > D str replace: python > lua > D C algorithm (with -O3): map tree set: 0.70s map tree get: 0.39s map tree clear: 0.23 chain set: 0.09s chain get: too large ... chain each: 0.05s variable length list set: 0.025s variable length list get: 0.01s variable length list each: 0.01s quick search find: 0.29s remalloc replace: 0.40s chain replace: 0.40s I think the one of problems is to!string(int) too slow, snprintf will better. | ||||
April 05, 2012 Re: benchmark dict list and string, D vs python vs lua | ||||
|---|---|---|---|---|
| ||||
Posted in reply to lzzll | On 4/5/12, lzzll <ownrepos@gmail.com> wrote: > I think the one of problems is to!string(int) too slow, snprintf > will better. Tables to the rescue: __gshared string[int] table; shared static this() { foreach (i; 0 .. MAX_RANGE) table[i] = to!string(i); } Then use table[i] instead of to!string(i). Here's a comparison: to!string: ---- test_dict ----- test dict set (1000000)... 1.281s test dict get (1000000)... 1.047s test dict clear (1000000)... 0.000s ---- test_list ----- test list set (1000000)... 0.125s test list get (1000000)... 0.000s test list each (1000000)... 0.000s ---- test_str ----- test str find (1000000)... 0.703s test str replace (1000000)... 1.016s table (http://pastebin.com/43Z4EwMj) test dict set (1000000)... 0.891s test dict get (1000000)... 0.109s test dict clear (1000000)... 0.000s ---- test_list ----- test list set (1000000)... 0.078s test list get (1000000)... 0.000s test list each (1000000)... 0.000s ---- test_str ----- test str find (1000000)... 0.125s test str replace (1000000)... 1.203s But it seems the str replace test got slower even though all the other tests got faster. | |||
April 05, 2012 Re: benchmark dict list and string, D vs python vs lua | ||||
|---|---|---|---|---|
| ||||
Posted in reply to lzzll | On 4/5/12 2:00 PM, lzzll wrote: > Hey, I wrote some code to benchmark dict list and string in D, python > and lua. > D is a great language, but some library look comparatively slow. > Some where may be wrong, I start D just today. [snip] Thanks for the benchmark, good comparisons are always helpful. > I think the one of problems is to!string(int) too slow, snprintf > will better. You're right. In fact I took a minute to adapt some C++ code I wrote for work into a faster to!string routine. On my machine I get: $ ./test.py ---- test_dict ----- test dict set (1000000)... 0.64s test dict get (1000000)... 0.40s test dict clear (1000000)... 0.09s ---- test_list ----- test list set (1000000)... 0.02s test list get (1000000)... 0.08s test list each (1000000)... 0.06s ---- test_str ----- test str find (1000000)... 0.47s test str replace (1000000)... 0.48s $ ./test ---- test_dict ----- test dict set (1000000)... 0.729s test dict get (1000000)... 0.261s test dict clear (1000000)... 0.000s ---- test_list ----- test list set (1000000)... 0.073s test list get (1000000)... 0.001s test list each (1000000)... 0.001s ---- test_str ----- test str find (1000000)... 0.593s test str replace (1000000)... 0.804s Not too shoddy! I'll work on adding the better conversion routine to Phobos. Andrei | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply