Skip to content

Commit d1e59c5

Browse files
committed
improve Elixir speed a bit
1 parent 72abf8b commit d1e59c5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The following results are for 123 unique utf-8 Bible text files in 23 languages
1616
2. Python 3.10.2 = 2.80s
1717
3. Julia 1.7.1 = 4.522
1818
4. Crystal 1.3.2 = 5.72s
19-
5. Elixir 1.13.2 = 8.37s
19+
5. Elixir 1.13.2 = 7.82s
2020
6. Ruby 3.1.0 = 8.31s
2121

2222
Golang 1.17 = UNDER REFACTORING, stay tuned

example-elixir/lib/words_extractor.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use Timex
33
defmodule WordsExtractor do
44
@moduledoc nil
55

6+
@pat Regex.compile!("[\W\d]+/u")
7+
68
def run do
79
outdir = "words"
810
File.rm_rf!(outdir)
@@ -31,7 +33,6 @@ defmodule WordsExtractor do
3133

3234
def worker({path, i}, outdir, count) do
3335
%{"code" => code, "lang" => lang} = YamlElixir.read_from_file!(path)
34-
pat = Regex.compile!("[\W\d]+/u")
3536

3637
filepath = String.replace(path, ".yml", ".txt")
3738
%File.Stat{:size => filesize} = File.stat!(filepath)
@@ -40,7 +41,7 @@ defmodule WordsExtractor do
4041
File.read!(filepath)
4142
|> String.downcase()
4243
|> String.trim()
43-
|> then(&Regex.split(pat, &1))
44+
|> then(&Regex.split(@pat, &1))
4445
|> MapSet.new()
4546
|> Enum.join("\n")
4647

0 commit comments

Comments
 (0)