File size: 1,315 Bytes
871e4fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "lease.hpp"
#include "distance.hpp"
#include <cstdio>
#include <chrono>
#include <cmath>
int main(){
 int checks=0;
 for(int w=2;w<45;++w)for(int h=2;h<31;++h){
  yeorin4::RectangleSpectrum s(w,h);
  for(double M:{0.,.1,1.,3.,12.}){
   auto a=s.at(M,.12);double m=0,e=0;
   for(int y=0;y<h;++y)for(int x=0;x<w;++x){double d=std::min(std::min(x,w-1-x),std::min(y,h-1-y));double z=std::min(M,.12*d);m+=z;e+=z*z;}
   if(std::abs(a.mean-m/(w*h))>1e-10||std::abs(a.energy-e/(w*h))>1e-9){std::fprintf(stderr,"spectrum mismatch\n");return 1;}++checks;
  }
 }
 yeorin4::Lease l;l.source=1;l.published=1;l.expires=2;l.a=16;l.energy=4;l.maximum=2;l.residual=10;
 yeorin4::Query q;q.source=1;q.now=1.2;auto r=yeorin4::revalidate(l,q);
 if(r.alpha!=1||std::abs(r.lower-28)>1e-12)return 2;
 volatile double sink=0;const int N=1000000;
 auto start=std::chrono::steady_clock::now();
 for(int i=0;i<N;++i){q.drift=(i%1000)*.001;auto d=yeorin4::revalidate(l,q);sink+=d.lower;}
 auto finish=std::chrono::steady_clock::now();
 double ns=std::chrono::duration<double,std::nano>(finish-start).count()/N;
 std::printf("{\"exact_spectrum_cases\":%d,\"lease_iterations\":%d,\"lease_nanoseconds_per_call\":%.6f,\"checksum\":%.6f,\"scope\":\"CPU arithmetic only, not end-to-end latency\"}\n",checks,N,ns,double(sink));
 return 0;
}