{"id":27334861,"url":"https://github.com/dmuth/google-go-monte-carlo","last_synced_at":"2025-04-12T14:46:30.401Z","repository":{"id":8343791,"uuid":"9902450","full_name":"dmuth/google-go-monte-carlo","owner":"dmuth","description":"A Monte Carlo simulation written in GoLang as a way to \"get my feet wet\" with the language.","archived":false,"fork":false,"pushed_at":"2020-09-03T22:21:49.000Z","size":31,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-06-19T04:04:52.333Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmuth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-07T02:43:19.000Z","updated_at":"2023-11-25T21:17:19.000Z","dependencies_parsed_at":"2022-08-07T03:00:30.973Z","dependency_job_id":null,"html_url":"https://github.com/dmuth/google-go-monte-carlo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fgoogle-go-monte-carlo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fgoogle-go-monte-carlo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fgoogle-go-monte-carlo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fgoogle-go-monte-carlo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmuth","download_url":"https://codeload.github.com/dmuth/google-go-monte-carlo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248585243,"owners_count":21128973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-12T14:46:29.582Z","updated_at":"2025-04-12T14:46:30.394Z","avatar_url":"https://github.com/dmuth.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Google Go Monte Carlo Simulation\n================================\n\nCode written in Google Go as a way to \"get my feet wet\" with the language.\n\n\nUsage\n-----\n\n    go run ./main.go [--chunk-size size] [--num-goroutines num] [--size size] [--random-md5] [--num-points num]\n\n    --chunk-size How many random numbers to send across channels at a time. Higher == more efficiency\n    --num-goroutines How many goroutines generating random numbers?\n    --size How big to make the square where points will be plotted?\n    --num-points - How many random numbers to generate?\n    --random-md5 Use the MD5 faux random number generator that I wrote\n\nPerformance\n-----------\n\nAll tests were done on my iMac with an Intel i7 CPU running at 3.4 Ghz.\nIt has 4 physical cores and each core has 2 virtual cores.\n\nSince Go saw the number of CPUs as 8, that's the setting I used.\nInstead of the actual random number generator, I used my MD5 faux \nrandom number generator. This helped me separate user CPU load from \nsystem CPU load (caused by messages being sent), which was most \nhelpful to me in troubleshooting.  I used version 1.0.3 of Google Go.\n\nOriginally, many channels were created (it helped me learn them in Go...), \nbut since the time to create a single random number is so low, the overhead \nof several messages sent across each channel for each random number \ngenerated was a problem.  Here is a list of the the changes I made and\ntheir improvements when running `go run ./main.go --size 100 --num-points 1000000`:\n\n- Original method: **13 seconds**\n- Modified random number generation to use a chunk size of 10K: **9.7 seconds**\n- Merged getPoints() and checkPoints(), eliminating 1 million writes \n\tto a channel: **7.7 seconds**\n- Changed Pi calculation to be at end of run without using messages, \n\tsaved another 1 million writes to a channel: **4.3 seconds**\n- Modified intNChannel() to return arrays of 2 random numbers instead \n\tof a random number at a time, saved yet another \n\t1 million channel writes: **2.5 seconds**\n- Modified intNChannel() to return arrays of array in a single message.\n\tWhen done in chunks of 10000 this is only 100 channel writes, \n\tsaving 999,900 writes: **1.6 seconds**\n\n\n**tl;dr Careful use of channels boosted script performance by 88%**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmuth%2Fgoogle-go-monte-carlo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmuth%2Fgoogle-go-monte-carlo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmuth%2Fgoogle-go-monte-carlo/lists"}