Skip to content
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

Add Julia category #20

Open
Jafagervik opened this issue Apr 24, 2024 · 6 comments
Open

Add Julia category #20

Jafagervik opened this issue Apr 24, 2024 · 6 comments
Assignees

Comments

@Jafagervik
Copy link
Contributor

Would be interesting to see what you could achieve with Julia for this challenge

@jcbhmr
Copy link
Member

jcbhmr commented Apr 24, 2024

sounds good! 👍 i invited you to the org if you want to spearhead that or link to an existing persons repo. 🚀

@Jafagervik
Copy link
Contributor Author

I can try to set up some repos and ask some uni friends if they wanna try!

@Jafagervik
Copy link
Contributor Author

I have the original code right here.

"""
    Extremely naive implementation of the 1BRC task.

Credit: https://www.youtube.com/watch?v=utTaPW32gKY
"""
function process_data(filepath::String)
    stats = Dict{String,Dict{String,Float32}}()

    open(filepath) do f
        for row in eachline(f)
            city, temp_str = split(row, ';')
            temp = parse(Float32, temp_str)

            if haskey(stats, city)
                city_stats = stats[city]
                # ifelse is faster than min/max
                city_stats["min"] = ifelse(temp < city_stats["min"], temp, city_stats["min"])
                city_stats["max"] = ifelse(temp > city_stats["max"], temp, city_stats["max"])
                city_stats["sum"] += temp
                city_stats["count"] += 1
            else
                stats[city] = Dict("min" => temp, "max" => temp, "sum" => temp, "count" => 1)
            end
        end
    end

    return stats
end

function print_stats(stats)
    for (city, city_stats) in stats
        min_temp = city_stats["min"]
        max_temp = city_stats["max"]
        avg_temp = city_stats["sum"] / city_stats["count"]
        println("$city: min=$min_temp, max=$max_temp, avg=$avg_temp")
    end
end

if abspath(PROGRAM_FILE) == @__FILE__
    filepath = length(ARGS) < 2 ? ARGS[2] : "data.txt"
    process_data(filepath) |> print_stats
end

I have yet to complete the more optimized one, but where do I go from here. Might have missed it in the docs!

@Jafagervik
Copy link
Contributor Author

https://github.com/Jafagervik/1BRC

Initial repo

@Jafagervik Jafagervik self-assigned this Apr 24, 2024
@jcbhmr
Copy link
Member

jcbhmr commented Apr 24, 2024

you can either add the repo as a link and host the competition/submissiosn under your username or add it to @1brc like the nodejs and bun stuff was added to this org. up to you 🤷‍♂️ do whatever you want lol

@vnegi10
Copy link

vnegi10 commented May 12, 2024

Would be interesting to see what you could achieve with Julia for this challenge

Indeed! I too have been playing with a Julia implementation last couple of weeks. I came here looking to open an issue, and found that you already beat me to it! 😄

I think we can share some notes in this discussion. I will also go through the Julia Discourse to gather more feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants