Git Product home page Git Product logo

Comments (7)

breezewish avatar breezewish commented on July 30, 2024

prometheus-go implements similar optimizations, but leaving a nicer interface (transparent to users): prometheus/client_golang@ae69392

from rust-prometheus.

siddontang avatar siddontang commented on July 30, 2024

cool, but we should support math.Trunc, and do a benchmark to compare Trunc + Int Atomic and Float Atomic.

from rust-prometheus.

breezewish avatar breezewish commented on July 30, 2024

yes. I will do a benchmark. If the performance impact of math.trunc is minimal, I prefer this way.

from rust-prometheus.

breezewish avatar breezewish commented on July 30, 2024

According to the benchmark, adding a trunc check (and uses float as interface) will slow down about 20%~30% compared to AtomicInt:

Mac:

test counter::bench_atomic_f64                          ... bench:          11 ns/iter (+/- 2)
test counter::bench_atomic_u64                          ... bench:           4 ns/iter (+/- 0)
test counter::bench_atomic_u64_trunc                    ... bench:           6 ns/iter (+/- 2)

Linux:

test counter::bench_atomic_f64                          ... bench:          11 ns/iter (+/- 1)
test counter::bench_atomic_u64                          ... bench:           6 ns/iter (+/- 0)
test counter::bench_atomic_u64_trunc                    ... bench:           8 ns/iter (+/- 0)

However it is still nearly 30%~50% faster than the AtomicFloat. In addition, the f64 is as slow as the RwLock implementation (with is used as a replacement without nightly).

from rust-prometheus.

siddontang avatar siddontang commented on July 30, 2024

how about using https://github.com/prometheus/client_golang/pull/367/files#diff-4eafde073feb6e8d8a2aefcc731b59c4R91 instead of math.Trunc?

from rust-prometheus.

breezewish avatar breezewish commented on July 30, 2024

According to the rust book,

Casting from a float to an integer will round the float towards zero.

I guess it is equal to if (v.round() as u64) as f64 == v. Will update the benchmark for this later.

from rust-prometheus.

breezewish avatar breezewish commented on July 30, 2024

Time consumption of these two are exactly the same.

from rust-prometheus.

Related Issues (20)

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.