Skip to content

Commit

Permalink
Remove time dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Dec 5, 2016
1 parent f106aa6 commit 98f56e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ Rust-PHF is a library to generate efficient lookup tables at compile time using
It currently uses the
[CHD algorithm](http://cmph.sourceforge.net/papers/esa09.pdf) and can generate
a 100,000 entry map in roughly .4 seconds. By default statistics are not
produced, but if you use the `phf_mac` crate with the `stats` feature enabled
(writing `phf_macros/stats` in the `[dependencies]` section of your
`Cargo.toml` instead of `phf_macros`) and set the environment variable
`PHF_STATS` it will issue a compiler note about how long it took.
produced, but if you set the environment variable `PHF_STATS` it will issue
a compiler note about how long it took.

Usage
=====
Expand Down
5 changes: 3 additions & 2 deletions phf_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ plugin = true
test = false

[features]
stats = ["time"]
unicase_support = ["unicase", "phf_shared/unicase"]

# Deprecated
stats = []

[dependencies]
phf_generator = { version = "=0.7.20", path = "../phf_generator" }
phf_shared = { version = "=0.7.20", path = "../phf_shared" }
time = { version = "0.1", optional = true }
unicase = { version = "1.4", optional = true }

[dev-dependencies]
Expand Down
17 changes: 5 additions & 12 deletions phf_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#![feature(plugin_registrar, quote, rustc_private)]

extern crate syntax;
#[cfg(feature = "stats")]
extern crate time;
extern crate rustc_plugin;
extern crate phf_shared;
extern crate phf_generator;
Expand All @@ -44,6 +42,7 @@ extern crate unicase;

use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::time::Instant;
use syntax::ast::{self, Expr, ExprKind, Mutability, TyKind};
use syntax::tokenstream::TokenTree;
use syntax::codemap::Span;
Expand Down Expand Up @@ -77,18 +76,12 @@ pub fn macro_registrar(reg: &mut Registry) {
}

fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState {
#[cfg(feature = "stats")]
use time::precise_time_s;
#[cfg(not(feature = "stats"))]
fn precise_time_s() -> f64 {
0.
}

let start = precise_time_s();
let start = Instant::now();
let state = phf_generator::generate_hash(entries);
let time = precise_time_s() - start;
let time = Instant::now() - start;

if cfg!(feature = "stats") && env::var_os("PHF_STATS").is_some() {
if env::var_os("PHF_STATS").is_some() {
let time = time.as_secs() as f64 + (time.subsec_nanos() as f64 / 1_000_000_000.);
cx.parse_sess
.span_diagnostic
.span_note_without_error(sp, &format!("PHF generation took {} seconds", time));
Expand Down

0 comments on commit 98f56e5

Please sign in to comment.