4 ms·
Working with strings in Erlang hasn't been much of a problem for me. The re module's ( http://erldocs.com/R14B/stdlib/re.html?i=0&search=re http://erldocs.com/
by chops 16y ago
Working with strings in Erlang hasn't been much of a problem for me. The re module's ( http://erldocs.com/R14B/stdlib/re.html?i=0&search=re http://erldocs.com/R14B/stdlib/re.html?i=0&search=re: ) regular expression handling is pretty decent, and it takes binaries, iolists, and of course normal strings (just lists of ints).
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&postdays=0&postorder=asc&start=0&sid=1f3dad84c9fa26085ca2b631425fae34 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.
- chops 16y agoI just did a followup test to see just how the re:replace function did with converting a 16kb text string with a BBCode parser I've written in Erlang, and on my crappy laptop it did 1000 conversions in 12 seconds. Further, I'm not running the high-performance version of Erlang, nor did I do any attempts at parallelization optimization. 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/bbcode.erl 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.
- silentbicycle 16y agoThat measurement would probably be more useful if stacked against same in Java / Python / Ruby / etc. Writing the parser itself in Erlang seems expensive; passing text through discount (http://www.pell.portland.or.us/~orc/Code/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)
- chops 16y agoAbsolutely. Perhaps I'll do a more elaborate comparison between a few other languages just to see.
- deleted 16y ago[deleted]
- silentbicycle 16y agoPeople coming from most other languages don't realize that atoms ("symbols", in Lisp) can be used for many things that would otherwise be done with strings. This really helps - pattern-matching on atoms is niiiice. Like much of Erlang, it makes lots of sense to people with Prolog experience, but ... who has Prolog experience? (lone hand) Oh. 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.