Up to Main Index                          Up to Journal for November, 2022

                  JOURNAL FOR WEDNESDAY 30TH NOVEMBER, 2022
______________________________________________________________________________

SUBJECT: Not a good month for the journal…
   DATE: Wed 30 Nov 20:15:25 GMT 2022

Only two posts this month, including this one :(

Work has been really busy and Mere has been progressing slowly. The number of
tests for operators and built-ins has risen from 2700 to 2980 asserts. The
quality of the tests has improved a lot and as a result many bugs fixed.

My ugly Bash script for testing has been replaced. Tests are now run using
Go’s standard testing framework:


  >go test ./mere/...
  ok    code.wolfmud.org/mere.git/mere  0.043s
  >


This also means I can generate coverage reports — which I’ve been using to
improve the tests:


  >go test -coverprofile cover.out ./mere/...
  ok    code.wolfmud.org/mere.git/mere  0.058s  coverage: 78.0% of statements
  >go tool cover -html=cover.out
  # This opens the code coverage report in a web browser…


Tests can be benchmarked and memory/CPU profiles are easier to obtain. For
anyone interested, a sample for the tests[1] and individual operators[2] is
included at the end. Note that the individual operator tests are still a work
in progress.

The tests are still written in Mere itself, but compiled and run under the
test framework:


  func TestMere(t *testing.T) {
    tests, _ := filepath.Glob(filepath.Join("..", "testdata", "*.mr"))
    for _, name := range tests {
      t.Run(name, func(t *testing.T) {
        src, _ := os.ReadFile(name)
        i := Compile(string(src))
        if i.Execute() != 0 {
          t.Fatal("")
        }
      })
    }
  }


For benchmarks, the tests are compiled once and executed multiple times. So
the times and allocations are only for executing the code, not compiling it:


  func BenchmarkMere(b *testing.B) {
    tests, _ := filepath.Glob(filepath.Join("..", "testdata", "*.mr"))
    for _, name := range tests {
      src, _ := os.ReadFile(name)
      I := Compile(string(src))
      b.Run(filepath.Base(name), func(b *testing.B) {
        for i := 0; i < b.N; i++ {
          if I.Copy().Execute() != 0 {
            b.Fatal("")
          }
        }
      })
    }
  }


The “compile once and run multiple” times is how I imagine WolfMUD will use
Mere. It’s already possible to run multiple instances of a compiled program. I
see Mere programs as small snippets, used when defining simple static rules in
zone files is not enough.

I’ve finished work for the day, written this and *poof* my evening has gone :(

At least the night is still young, perfect time for coding ;)

--
Diddymus

  [1] Sample benchmark run of the tests:

  >go test -bench="Mere" -benchmem ./mere/...
  goos: linux
  goarch: amd64
  pkg: code.wolfmud.org/mere.git/mere
  cpu: Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
  B…/b_assert.mr-4        22419   52182 ns/op   16405 B/op   138 allocs/op
  B…/b_bool_array.mr-4    13854   88076 ns/op   20855 B/op   218 allocs/op
  B…/b_bool_map.mr-4       5790  214657 ns/op   53233 B/op   496 allocs/op
  B…/b_delete.mr-4         5842  192327 ns/op   42835 B/op   491 allocs/op
  B…/b_exists.mr-4        14170   89446 ns/op   22407 B/op   216 allocs/op
  B…/b_float_array.mr-4   10000  100019 ns/op   29358 B/op   226 allocs/op
  B…/b_gosub.mr-4        135493    8859 ns/op    2447 B/op    42 allocs/op
  B…/b_goto.mr-4         176642    8164 ns/op    2327 B/op    38 allocs/op
  B…/b_int_array.mr-4     10000  102459 ns/op   29183 B/op   221 allocs/op
  B…/b_int_map.mr-4        7322  162947 ns/op   39545 B/op   364 allocs/op
  B…/b_keys.mr-4          49760   23224 ns/op    6897 B/op    92 allocs/op
  B…/b_len.mr-4           30273   41743 ns/op   13609 B/op   110 allocs/op
  B…/b_literal.mr-4        4849  282871 ns/op   61154 B/op  1151 allocs/op
  B…/b_sort.mr-4          17623   64587 ns/op   15585 B/op   130 allocs/op
  B…/b_sprint.mr-4        15076   78952 ns/op   17465 B/op   405 allocs/op
  B…/b_string_array.mr-4  10000  106694 ns/op   38255 B/op   204 allocs/op
  B…/b_substr.mr-4       106426   11535 ns/op    2684 B/op    57 allocs/op
  B…/issues.mr-4          20940   57074 ns/op    6896 B/op   117 allocs/op
  B…/op_add.mr-4          28041   43080 ns/op    9151 B/op   135 allocs/op
  B…/op_and.mr-4          82416   16425 ns/op    3430 B/op    35 allocs/op
  B…/op_assign.mr-4        3574  324021 ns/op   66738 B/op   574 allocs/op
  B…/op_bool.mr-4         42499   31609 ns/op    6544 B/op    70 allocs/op
  B…/op_dec.mr-4          67170   21144 ns/op    5381 B/op    67 allocs/op
  B…/op_div.mr-4          58701   18942 ns/op    3780 B/op    57 allocs/op
  B…/op_eq.mr-4            9580  129701 ns/op   24062 B/op   242 allocs/op
  B…/op_float.mr-4        20192   57297 ns/op    7606 B/op   101 allocs/op
  B…/op_ge.mr-4           22231   56760 ns/op    8419 B/op    92 allocs/op
  B…/op_gt.mr-4           22413   57269 ns/op    8419 B/op    92 allocs/op
  B…/op_inc.mr-4          54649   21648 ns/op    5381 B/op    67 allocs/op
  B…/op_index.mr-4        14078   90335 ns/op   19102 B/op   217 allocs/op
  B…/op_index_assign.mr-4  1579  819121 ns/op  108057 B/op  1121 allocs/op
  B…/op_int.mr-4          44778   28096 ns/op    6729 B/op    76 allocs/op
  B…/op_land.mr-4         84967   15305 ns/op    2768 B/op    34 allocs/op
  B…/op_le.mr-4           21312   55594 ns/op    8417 B/op    92 allocs/op
  B…/op_lor.mr-4          77998   17538 ns/op    3184 B/op    35 allocs/op
  B…/op_lt.mr-4           21922   57425 ns/op    8417 B/op    92 allocs/op
  B…/op_mod.mr-4          19261   61334 ns/op    8130 B/op   147 allocs/op
  B…/op_mult.mr-4         54520   23925 ns/op    4558 B/op    76 allocs/op
  B…/op_mult_assign.mr-4 257280    5560 ns/op    1765 B/op    23 allocs/op
  B…/op_ne.mr-4           13566   88211 ns/op   16562 B/op   137 allocs/op
  B…/op_neg.mr-4         119104   12198 ns/op    2980 B/op    54 allocs/op
  B…/op_not.mr-4         154328    9547 ns/op    2768 B/op    34 allocs/op
  B…/op_or.mr-4           89485   15911 ns/op    3427 B/op    35 allocs/op
  B…/op_shift_left.mr-4   93109   15644 ns/op    3809 B/op    46 allocs/op
  B…/op_shift_right.mr-4 113055   12560 ns/op    3160 B/op    36 allocs/op
  B…/op_spaceship.mr-4    16782   71610 ns/op   11064 B/op   190 allocs/op
  B…/op_string.mr-4       21387   59520 ns/op   12164 B/op   226 allocs/op
  B…/op_sub.mr-4          45928   29858 ns/op    6128 B/op   107 allocs/op
  B…/op_type.mr-4         47056   29723 ns/op    8046 B/op   117 allocs/op
  B…/op_xor.mr-4          68089   16569 ns/op    3426 B/op    35 allocs/op
  PASS
  ok      code.wolfmud.org/mere.git/mere  78.608s


  [2] Sample benchmark run of individual operators:

  >go test -bench="Ops" -benchmem ./mere/...
  goos: linux
  goarch: amd64
  pkg: code.wolfmud.org/mere.git/mere
  cpu: Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
  BenchmarkOps/b-4          724317  1963 ns/op  1200 B/op  18 allocs/op
  BenchmarkOps/b=-4         503775  2368 ns/op  1248 B/op  19 allocs/op
  BenchmarkOps/b=b-4        589674  2378 ns/op  1248 B/op  19 allocs/op
  BenchmarkOps/ba-4         708888  1944 ns/op  1392 B/op  18 allocs/op
  BenchmarkOps/bm-4         590388  1934 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/f-4          623192  1925 ns/op  1248 B/op  18 allocs/op
  BenchmarkOps/f=-4         528535  2215 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/f=Af+Af-4    452374  2531 ns/op  1400 B/op  21 allocs/op
  BenchmarkOps/f=f-4        531918  2393 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/f=f+f-4      452587  2853 ns/op  1400 B/op  21 allocs/op
  BenchmarkOps/fa-4         586860  1898 ns/op  1392 B/op  18 allocs/op
  BenchmarkOps/fm-4         604845  2060 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/i-4          725466  1875 ns/op  1248 B/op  18 allocs/op
  BenchmarkOps/i=-4         572564  2207 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/i=Ai+Ai-4    543379  2586 ns/op  1392 B/op  20 allocs/op
  BenchmarkOps/i=i-4        594530  2434 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/i=i+i-4      483459  2684 ns/op  1392 B/op  20 allocs/op
  BenchmarkOps/ia-4         609939  1977 ns/op  1392 B/op  18 allocs/op
  BenchmarkOps/im-4         574332  2147 ns/op  1296 B/op  19 allocs/op
  BenchmarkOps/s-4          688345  1917 ns/op  1312 B/op  18 allocs/op
  BenchmarkOps/s=-4         591752  2403 ns/op  1360 B/op  19 allocs/op
  BenchmarkOps/s=As+As-4    525708  2745 ns/op  1474 B/op  22 allocs/op
  BenchmarkOps/s=s-4        506758  2560 ns/op  1360 B/op  19 allocs/op
  BenchmarkOps/s=s+s-4      489769  2903 ns/op  1474 B/op  22 allocs/op
  BenchmarkOps/sa-4         562858  2046 ns/op  1392 B/op  18 allocs/op
  BenchmarkOps/sm-4         687019  2017 ns/op  1296 B/op  19 allocs/op
  PASS
  ok      code.wolfmud.org/mere.git/mere  35.197s



  Up to Main Index                          Up to Journal for November, 2022