Remember
Register
Pre Exam Test Practice (
SSC

Banking

IAS

GATE

State Level

CLAT

Railways

Insurance

Teaching Exams

NDA

Defence

IES

State Exam
)
Pre Exam Test Practice
All Activity
Tags
Users
Ask a Question
About Boostr
Advertise on boostr.in
Jobs
Pre Exam Test Practice (
SSC

Banking

IAS

GATE

State Level

CLAT

Railways

Insurance

Teaching Exams

NDA

Defence

IES

State Exam
)
Organizational Research By
Surprising Reserch Topic
why is elixir slowest among ruby and golang in solving project euler 5
why is elixir slowest among ruby and golang in solving project euler 5 Â using 'performance,elixir,numericalcomputing'
I'm working on Project Euler problems in multiple languages just to see how productive and how fast languages are. In problem #5, we are asked to find the smallest positive number that is evenly divisible by all of the numbers from 1 to 20.
I implemented the solution in multiple languages. Here are the stats:
Golang 1.4.2 : ~0.58s
Ruby 2.2 MRI : ~6.7s
Elixir 1.0.5 : ~57s
Why is Elixir's performance so slow? I tried using the same optimizations in all languages. Caveat: I'm a FP and Elixir newbie.
Is there anything I can do to improve the performance in Elixir? If you used any profiling tools in figuring out a better solution, could you please include them in the response?
In Golang:
func problem005() int {
Â Â i := 20
outer:
Â Â for {
Â Â Â Â for j := 20; j > 0; j {
Â Â Â Â Â Â if i%j != 0 {
Â Â Â Â Â Â Â Â i = i + 20
Â Â Â Â Â Â Â Â continue outer
Â Â Â Â Â Â }
Â Â Â Â }
Â Â Â Â return i
Â Â }
Â Â panic("Should have found a solution by now")
}
In Ruby:
def self.problem005
Â Â divisors = (1..20).to_a.reverse
Â Â number = 20 # we iterate over multiples of 20
Â Â until divisors.all? { divisor number % divisor == 0 } do
Â Â Â Â number += 20
Â Â end
Â Â return number
end
In Elixir:
def problem005 do
Â Â divisible_all? = fn num >
Â Â Â Â Enum.all?((20..2), &(rem(num, &1) == 0))
Â Â end
Â Â Stream.iterate(20, &(&1 + 20))
Â Â > Stream.filter(divisible_all?)
Â Â > Enum.fetch! 0
end
Â Â Â Â
performance
elixir
numericalcomputing
asked
Sep 7, 2015
by
rajesh
Please
log in
or
register
to add a comment.
0
votes
6
views
Related Hot Questions
Government Jobs Opening
...