Up to Main Index                              Up to Journal for July, 2023

                      JOURNAL FOR MONDAY 3RD JULY, 2023
______________________________________________________________________________

SUBJECT: High Throughput Fizz Buzz
   DATE: Mon  3 Jul 20:15:43 BST 2023

I did hope to get another post written for June along with a new release of
Mere ICE. However, the documentation is taking longer to update than I thought
it would. I also found bugs that need fixing. More on that in another post.

In the meantime, I came across a StackExchange post about high throughput Fizz
Buzz[1] which piqued my interest.

The naïve implementation, a modified Mere ICE example, gets around 10½MiB/sec


    loop = 1
    next:
      if loop % 3 == 0; print "fizz"
      if loop % 5 == 0; print "buzz"
      if loop % 3 != 0 && loop % 5 != 0; print loop
      println
      loop++
    goto next


After looking through other submissions and a little coffee break tinkering, I
came up with a Mere version of a modified Python submission:


    cycle = []string (
      "FizzBuzz", "", "", "Fizz", "",
      "Buzz", "Fizz", "", "", "Fizz",
      "Buzz", "", "Fizz", "", "",
    )
    x = 1
    xloop:
      if (c = cycle[x % 15]) == ""; c = x
      println c
      x++
    goto xloop


The throughput for this version is around 16MiB/sec. Not fantastic, but not
too shabby for a home-brew language under development. Both of the above Mere
programs used a tweaked command line version of Mere. By default Mere writes
to the plain unbuffered os.Stdout:


    func main() {
      f, _ := os.ReadFile(os.Args[1])
      os.Exit(mere.Compile(string(f)).Execute())
    }

Mere is designed for easy embedding, so a simple tweak:

    func main() {
      f, _ := os.ReadFile(os.Args[1])
      c := mere.Compile(string(f))
      c.Stdout = bufio.NewWriterSize(c.Stdout, 1024*1024*16)
      os.Exit(c.Execute())
    }


If I made the output buffer larger than 16Mib the output wasn’t continuous
making measurement difficult.

This was a fun little exercise :) I think I should include this as another
standard benchmark for Mere.

Current Fizz Buzz leader gets 54-56GiB/s using hand crafted assembly language…

--
Diddymus

  [1] High Throughput Fizz Buzz:
      https://codegolf.stackexchange.com/questions/215216/high-throughput-fizz-buzz/236630


  Up to Main Index                              Up to Journal for July, 2023