-
Notifications
You must be signed in to change notification settings - Fork 335
Julia: update benchmark code #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,5 @@ | ||
| # base case 1 | ||
| fibonacci(::Val{0}) = 0 | ||
| # base case 2 | ||
| fibonacci(::Val{1}) = 1 | ||
| # general case | ||
| fibonacci(::Val{n}) where n = fibonacci(Val(n-1)) + fibonacci(Val(n-2)) | ||
| fibonacci(n) = n < 2 ? n : fibonacci(n-1) + fibonacci(n-2) | ||
|
|
||
| let | ||
| u = parse(Int,ARGS[1]) | ||
| r = 0 | ||
| for i ∈ 1:u | ||
| r += fibonacci(Val(i)) | ||
| end | ||
| println(r) | ||
| end | ||
| main(u) = println(sum(fibonacci, 1:u)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain if / how this is equivalent to the loop?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The If you're prioritizing making the implementations more uniform between languages rather than using more idiomatic language constructs, going back to a loop is just fine. Let me know. |
||
|
|
||
| isinteractive() || main(parse(Int, ARGS[1])) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| let | ||
| function main(u) | ||
| a = zeros(Int,10^4) | ||
| u = parse(Int,ARGS[1]) | ||
| r = rand(1:10^4) | ||
| @inbounds for i ∈ 1:10^4 | ||
| @inbounds for j ∈ 1:10^5 | ||
| a[i] = a[i] + j%u | ||
| for i ∈ 1:10^4 | ||
| for j ∈ 1:10^5 | ||
| a[i] += j%u | ||
| end | ||
| a[i] = a[i] + r | ||
| a[i] += r | ||
| end | ||
| println(a[r]) | ||
| end | ||
| end | ||
|
|
||
| isinteractive() || main(parse(Int, first(ARGS))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to go back to having an if / case for 0 and 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
(n == 0 || no == 1) ? n : fibonacci(n-1) + fibonacci(n-2)okay, or does it need to be the full