![]() # Benchmark on some randomly selected small foo(v) setup=(v = rand(1:1000)) # Wrapped in $() to stop the compiler foo($(100)) We can do that with: using BenchmarkTools When benchmarking code, we generally take the minimum time from several runs of the code. If you’re a performance enthusiast, you might like to check out the benchmarking notes below because it’s easy to measure the wrong thing. The example solutions below are roughly in run time order (fastest first), but all of them are satisfactory solutions to the problem. Simpler or more flexible solutions construct strings through concatenation. The fastest solutions avoid constructing new strings unless they have to and instead return one of several statically allocated strings when n is divisible by 3, 5, or 7. You can solve this exercise a great number of ways! Here’s a link and an excerpt in a spoiler for anyone interested. ![]() The notes show a variety of ways to solve the problem and try to explain the trade-offs. The reason we were looking into this was to improve our mentoring notes for this exercise on exercism. Have a look at this, to see some of the solutions we’ve experimented with so far. I’m measuring the solutions with this benchmark. If somebody has a clean way to do that, that would be interesting as well. ![]() So you can only have "Pling", "Plang", "Plong" as literal strings in your solution.Ĭompact concatenating solution function raindrops(number)Ī third category may be solutions which use a macro to generate the tree / lookup table. In this category you must make use of the concatenating logic of the problem. Tree of if / else solution function raindrops(number) In this category you just have to find the fastest possible solution. does not have any of 3, 5, or 7 as a factor, the result should be the digits of the number.Ĭan any of you find more performant solutions? There are two categories.has 7 as a factor, add ‘Plong’ to the result.has 5 as a factor, add ‘Plang’ to the result.has 3 as a factor, add ‘Pling’ to the result.So, and I have been discussing the raindrops exercise in Exercism and solutions to it.Ĭreate a function raindrops, which will return a string given a number as follows:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |