Giter VIP home page Giter VIP logo

metriq's Introduction

Metriq - Logging for Solana Smart Contracts

What Is It

Provides functions to produce structured logs in solana smart contracts.

See benchmarks for speed comparisons.

Usage

Add to Cargo.toml:

metriq = "0.1.0"

In your code:

use metriq;
use metriq::FastDisplay;

fn example_function() {
    // Output: some log message^another message^
    metriq::log!("some log message", "another message");
    // Output: key1`value^key2`1^key3`b1^key4`b0^
    metriq::log!(
        metriq::kv("key1", "value"),
        metriq::kv("key2", 1),
        metriq::kv("key3", true),
        metriq::kv("key4", false),
    );
}

metriq::kv accepts a &str key and any value which implements the metriq::FastDisplay trait.

The delimiter between messages in a log! is set to ^ and the delimiter between key value pairs is set to `.

true gets converted to b1. false gets converted to b0.

Benchmarks

Benchmarks compare speed of formatting using format! and metriq::fast_fmt!.

type format! metriq::fast_fmt!
Pubkey 2.8627 us 2.7455 us
&str 248.97 ns 225.68 ns
i32 105.85 ns 75.998 ns
ui32 97.742 ns 73.063 ns
key pair (value == &str) 254.15 ns 207.01 ns

Ran on:

MacBook Pro (16-inch, 2019)
2.4 GHz 8-Core Intel Core i9
32 GB 2667 MHz DDR4
30% Battery

Development

To run benchmarks: cargo bench

metriq's People

Stargazers

Shahmeer Navid avatar

Watchers

Shahmeer Navid avatar

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.