Skip to content

Getting time and formatting it seems slow. #94

@dpc

Description

@dpc

Working on slog-rs - a logger, I've been doing some benchmarking, and getting a current timestamp (formatted) from chrono is taking a lot of time.

Fist I've discovered that just taking time (without formatting) takes around 60ns in my benchmarks. Does it require doing two syscalls (one for time, one for timezone)? I've filled rust-lang/rust#36358 to inquire why it isn't faster.

Second formatting is taking around 500ns, which seems too much. I wish formatting provided something like fn fmt_rfc3339<W : io::Write>(&self, io : W) -> io::Result<()> which does not require any allocation. Also, when investigating the code, it seems there's a lot of cloned() calls, and the whole thing is based on StrftimeItems which like printf in C: scans the format every time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions