Git Product home page Git Product logo

Comments (7)

MengRao avatar MengRao commented on June 10, 2024 1

我修改了下test.cc,去掉了<bits/stdc++.h>,并去掉了sleep1秒的注释,这样可以大大提高精度降低误差

from tscns.

MengRao avatar MengRao commented on June 10, 2024 1

只需要init一次,可以重复calibrate,这样不用等10ms,也不会有多线程问题

from tscns.

ktprime avatar ktprime commented on June 10, 2024

多路上面可能不准,通常情况下要定期校验,
多线程情况下周期性调用init 是否有问题?

include <bits/stdc++.h> 在macOS clang++上无法编译,似乎已经不是c++标准头文件了(gcc 保留)

from tscns.

MengRao avatar MengRao commented on June 10, 2024

可以周期性重复调用calibrate(),这是多线程安全的

from tscns.

ktprime avatar ktprime commented on June 10, 2024

服务器跨平台使用修改rdsysns,使用steady_clock 是否比high_resolution_clock 更稳定 还是没太大区别?

改成steady_clock 后,测试数据不一样,b2c 数据误差持续变大
a: 14642789863999881, b: 14642789864006251, c: 14642789864006229, a2b: 6370, b2c: -22, good: 0, rdsysns_latency: 6339
a: 14642790864015103, b: 14642790864021136, c: 14642790864021107, a2b: 6033, b2c: -29, good: 0, rdsysns_latency: 5995
a: 14642791864033885, b: 14642791864034313, c: 14642791864034287, a2b: 428, b2c: -26, good: 0, rdsysns_latency: 393
a: 14642792864040781, b: 14642792864041466, c: 14642792864041427, a2b: 685, b2c: -39, good: 0, rdsysns_latency: 637
...
a: 14643039691289192, b: 14643039691290108, c: 14643039691289648, a2b: 916, b2c: -460, good: 0, rdsysns_latency: 447
a: 14643040691297430, b: 14643040691298408, c: 14643040691297938, a2b: 978, b2c: -470, good: 0, rdsysns_latency: 499

定期同步校验init()每次至少10ms等待, 对于服务器有点卡

from tscns.

ktprime avatar ktprime commented on June 10, 2024

下面这段代码每200ms运行一次,为减少同步卡顿,做了如下校验不知是否有问题

void Clock::AdjustTime() const
{
    const auto nowns = tn.rdns();
    const auto nowss = tn.rdsysns(); //steady clock
    if (std::abs(nowns - nowss) > 1000)
       tn.init();
}
  1. 调整后的时钟是否因为较准往前回拨?
  2. ns_offset 变量(不同线程读写不会有同步问题?)

from tscns.

ktprime avatar ktprime commented on June 10, 2024

笔记本上使用发现时间漂移比较严重,盒盖再翻盖后时钟误差巨大,甚至出现回拨现象,按如下解决

void Clock::AdjustTime() const
{
    const auto nowns = tn.rdns();
    const auto nowss = tn.rdsysns(); //steady clock
    if (std::abs(nowns - nowss) > 10'000) //误差比较大,频率可能发生较大变化
       tn.init();
    else if (std::abs(nowns - nowss) > 1000) //小范围内对齐
       tn.calibrate();

}

from tscns.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.