proj icon indicating copy to clipboard operation
proj copied to clipboard

Benchmark against C

Open mpgerlek opened this issue 6 years ago • 3 comments

We need to run something like the UTM example case over a zillion points, and see how it compares to the C code.

mpgerlek avatar Apr 14 '18 00:04 mpgerlek

We timed just the Forward() operation, using the BenchmarkConvert* tests in package operations and using the code in PROJ4's example app. Inputs are (12.0,55.0). The runs were done on mpg's laptop and compiled with Go 1.10.

  • +proj=utm +zone=32 +ellps=GRS80
    • C: 375 ns/op
    • Go: 566ns/op
  • +proj=aea +ellps=GRS80 +lat_1=0 +lat_2=2
    • C: 147 ns/op
    • Go: 160 ns/op
  • +proj=airy +a=6400000 +lat_1=0 +lat_2=2
    • C: 137 ns/op
    • Go: 185 ns/op

In all three Go examples, ~40-60% of the time was spend in the math package. Most of the remaining time was in functions like Forward(), forwardPrepare(), Qsfn(), and such. There were no obvious gotchas.

I'm surprised at the size of the deltas for the utm and airy tests. Someday, someone should examine these more closely.

mpgerlek avatar Apr 20 '18 18:04 mpgerlek

@mpgerlek I would be interested in seeing the pprof graph if you have it handy.

ARolek avatar Apr 20 '18 18:04 ARolek

I didn't save the files, but here's some anecdotal snips from my the scrollback of my terminal window:


Showing top 10 nodes out of 63
      flat  flat%   sum%        cum   cum%
     400ms 21.39% 21.39%      400ms 21.39%  math.sin
     360ms 19.25% 40.64%     1670ms 89.30%  github.com/go-spatial/proj/operations.(*Airy).Forward
     300ms 16.04% 56.68%      300ms 16.04%  math.Log
     240ms 12.83% 69.52%      260ms 13.90%  math.cos
     110ms  5.88% 75.40%      310ms 16.58%  runtime.mallocgc
     100ms  5.35% 80.75%      100ms  5.35%  runtime.kevent
      60ms  3.21% 83.96%       60ms  3.21%  github.com/go-spatial/proj/core.(*ConvertLPToXY).forwardPrepare
      50ms  2.67% 86.63%       50ms  2.67%  github.com/go-spatial/proj/core.(*ConvertLPToXY).forwardFinalize
      40ms  2.14% 88.77%       40ms  2.14%  runtime.mach_semaphore_wait
      30ms  1.60% 90.37%       30ms  1.60%  runtime.nextFreeFast (inline)

Showing top 20 nodes out of 67
      flat  flat%   sum%        cum   cum%
     0.34s 21.79% 21.79%      0.37s 23.72%  math.sin
     0.29s 18.59% 40.38%      0.29s 18.59%  math.Log
     0.21s 13.46% 53.85%      1.36s 87.18%  github.com/go-spatial/proj/operations.(*Aea).Forward
     0.20s 12.82% 66.67%      0.49s 31.41%  github.com/go-spatial/proj/support.Qsfn
     0.08s  5.13% 71.79%      0.09s  5.77%  github.com/go-spatial/proj/core.(*ConvertLPToXY).forwardPrepare
     0.06s  3.85% 75.64%      0.23s 14.74%  runtime.mallocgc
     0.04s  2.56% 78.21%      0.04s  2.56%  runtime.memclrNoHeapPointers
     0.03s  1.92% 80.13%      0.03s  1.92%  github.com/go-spatial/proj/core.(*ConvertLPToXY).forwardFinalize (inline)
     0.03s  1.92% 82.05%      0.03s  1.92%  math.IsInf (inline)
     0.03s  1.92% 83.97%      0.03s  1.92%  math.cos
     0.03s  1.92% 85.90%      0.03s  1.92%  runtime.mach_semaphore_signal
     0.03s  1.92% 87.82%      0.03s  1.92%  runtime.nextFreeFast (inline)
     0.02s  1.28% 89.10%      0.02s  1.28%  runtime.(*mspan).init (inline)
     0.02s  1.28% 90.38%      0.02s  1.28%  runtime.mach_semaphore_timedwait
     0.02s  1.28% 91.67%      0.25s 16.03%  runtime.newobject
     0.01s  0.64% 92.31%      1.49s 95.51%  github.com/go-spatial/proj/core.(*ConvertLPToXY).Forward
     0.01s  0.64% 92.95%      1.50s 96.15%  github.com/go-spatial/proj/operations_test.BenchmarkConvertAea
     0.01s  0.64% 93.59%      0.01s  0.64%  github.com/go-spatial/proj/support.Adjlon (inline)
     0.01s  0.64% 94.23%      0.01s  0.64%  math.Cos
     0.01s  0.64% 94.87%      0.01s  0.64%  runtime.(*gcBitsArena).tryAlloc (inline)

Showing top 10 nodes out of 47
      flat  flat%   sum%        cum   cum%
     340ms 15.04% 15.04%      360ms 15.93%  math.Sincos
     220ms  9.73% 24.78%     2190ms 96.90%  github.com/go-spatial/proj/operations.(*EtMerc).Forward
     190ms  8.41% 33.19%      190ms  8.41%  math.xatan (inline)
     180ms  7.96% 41.15%      520ms 23.01%  github.com/go-spatial/proj/operations.clenS
     170ms  7.52% 48.67%      170ms  7.52%  math.Exp
     140ms  6.19% 54.87%      140ms  6.19%  math.Log
      80ms  3.54% 58.41%      350ms 15.49%  github.com/go-spatial/proj/operations.asinhy
      80ms  3.54% 61.95%       80ms  3.54%  math.Hypot
      70ms  3.10% 65.04%       90ms  3.98%  math.tan
      60ms  2.65% 67.70%      200ms  8.85%  github.com/go-spatial/proj/operations.log1py

mpgerlek avatar Apr 20 '18 18:04 mpgerlek