by icey · 16y ago · 0 comments
Erlang strings are just lists of ints, but it's important to know the speed consequences with dealing with the ++ operator, or lists:flatten (which is supposed to be pretty slow, or so I've heard - never personally benchmarked). Binaries, on the other hand, are more like typical strings in other languages, and don't have the same performance penalty.
I'd say: play with it, do some benchmarks, and see how it fits for you. It's pretty easy to tinker with things on the Erlang Shell (like any REPL) so go for it. If it doesn't work well enough for you, ask the Erlang Mailing list, which is pretty good at ferreting out speed improvements (recent relevant optimization thread: http://www.trapexit.org/forum/viewtopic.php?t=19541&post... ).
And if all that fails for you, then you at least know you gave it a shot and can rule it out.
Personally, I think the language is freakin' awesome.
Many of the performance issues (++, etc.) apply to any language with immutable strings, or any other immutable data structures. Clojure, Haskell, etc., but nobody harasses Clojure about being "bad for strings" - There's just a FUD meme about Erlang going around.
You can also do string handling via a port (an external program in C, or any other language), if it's a major performance issue - Erlang is happy to pass messages to an external program in any language. Lua has a similar design* . It focuses on doing certain things really well, and for the rest, there's an easy escape; no harm, no foul. "You want to run some eeevil code? Just run it in another process, we'll send data to it and handle the results if ze sleazy bastard doesn't crash..."
* And immutable strings - In Lua, all strings are atoms by default.
Surprising to me was that the performance difference between binaries and strings wasn't too much different.
Module: https://github.com/choptastic/Yabbie/blob/linux/site/src/lib...
(keep in mind, this is built with the Nitrogen Web Framework in mind, so if you want to run it stand-alone, you can comment out the include lines and it should work just fine).
(nitrogen@127.0.0.1)9> bbcode:benchmark("l4d.txt",1000).
[{binary_time,12841.423},{string_time,12888.905}]
So 12000 milliseconds for 1000 iterations each. A few millisecond difference (46 millisecond difference) isn't much of a difference.Writing the parser itself in Erlang seems expensive; passing text through discount (http://www.pell.portland.or.us/~orc/Code/discount/) in an otherwise Erlang system seems like a good neutral measure.
(and then 100k threads doing same concurrently)