<commit_before>/*
 * Copyright (c) 2013, <NAME> (<EMAIL>)
 *
 * See the LICENSE file in the capnproto-rust root directory.
 */

#[feature(globs)];
#[feature(macro_rules)];

#[link(name = "capnproto-rust-benchmark", vers = "alpha", author = "dwrensha")];

#[crate_type = "bin"];

extern mod capnprust;

pub mod common;

pub mod carsales_capnp;
pub mod carsales;

pub mod catrank_capnp;
pub mod catrank;

pub mod eval_capnp;
pub mod eval;

macro_rules! passByObject(
    ( $testcase:ident, $iters:expr ) => ({
            let mut rng = ~common::FastRand::new();
            for _ in range(0, $iters) {
                let messageReq = capnprust::message::MessageBuilder::new_default();
                let messageRes = capnprust::message::MessageBuilder::new_default();


                let request = messageReq.initRoot::<$testcase::RequestBuilder>();
                let response = messageRes.initRoot::<$testcase::ResponseBuilder>();
                let expected = $testcase::setupRequest(rng, request);

                do request.asReader |requestReader| {
                    $testcase::handleRequest(requestReader, response);
                }

                do response.asReader |responseReader| {
                    if (! $testcase::checkResponse(responseReader, expected)) {
                        println("Incorrect response.");
                    }
                }

                messageReq.release();
                messageRes.release();
            }
        });
    )


pub fn main () {

    let args = std::os::args();

    if (args.len() != 5) {
        println!("USAGE: {} MODE REUSE COMPRESSION ITERATION_COUNT", args[0]);
        return;
    }

    let iters = match from_str::<u64>(args[4]) {
        Some (n) => n,
        None => {
            println!("Could not parse a u64 from: {}", args[4]);
            return;
        }
    };

/* TODO use std::run
    unsafe {
        let child = funcs::posix88::unistd::fork();
        if (child == 0 ) {
            printfln!("%s", "Hello world. I am the child and client.");
        } else {
            printfln!("%s", "Hello world. I am the parent and server.");
        }
    }
*/

//    passByObject!(catrank, iters);
    passByObject!(carsales, iters);
//    passByObject!(eval, iters);

}<commit_msg>now you can specify the benchmark testcase on the command line<commit_after>/*
 * Copyright (c) 2013, <NAME> (<EMAIL>)
 *
 * See the LICENSE file in the capnproto-rust root directory.
 */

#[feature(globs)];
#[feature(macro_rules)];

#[link(name = "capnproto-rust-benchmark", vers = "alpha", author = "dwrensha")];

#[crate_type = "bin"];

extern mod capnprust;

pub mod common;

pub mod carsales_capnp;
pub mod carsales;

pub mod catrank_capnp;
pub mod catrank;

pub mod eval_capnp;
pub mod eval;

macro_rules! passByObject(
    ( $testcase:ident, $iters:expr ) => ({
            let mut rng = ~common::FastRand::new();
            for _ in range(0, $iters) {
                let messageReq = capnprust::message::MessageBuilder::new_default();
                let messageRes = capnprust::message::MessageBuilder::new_default();


                let request = messageReq.initRoot::<$testcase::RequestBuilder>();
                let response = messageRes.initRoot::<$testcase::ResponseBuilder>();
                let expected = $testcase::setupRequest(rng, request);

                do request.asReader |requestReader| {
                    $testcase::handleRequest(requestReader, response);
                }

                do response.asReader |responseReader| {
                    if (! $testcase::checkResponse(responseReader, expected)) {
                        println("Incorrect response.");
                    }
                }

                messageReq.release();
                messageRes.release();
            }
        });
    )

macro_rules! doTestcase(
    ( $testcase:ident, $mode:expr, $reuse:expr, $compression:expr, $iters:expr ) => ({
            match $mode {
                ~"object" => passByObject!($testcase, $iters),
                s => fail!("unrecognized mode: {}", s)
            }
        });
    )



pub fn main () {

    let args = std::os::args();

    if (args.len() != 6) {
        println!("USAGE: {} CASE MODE REUSE COMPRESSION ITERATION_COUNT", args[0]);
        return;
    }

    let iters = match from_str::<u64>(args[5]) {
        Some (n) => n,
        None => {
            println!("Could not parse a u64 from: {}", args[5]);
            return;
        }
    };

/* TODO use std::run
    unsafe {
        let child = funcs::posix88::unistd::fork();
        if (child == 0 ) {
            printfln!("%s", "Hello world. I am the child and client.");
        } else {
            printfln!("%s", "Hello world. I am the parent and server.");
        }
    }
*/


    match args[1] {
        ~"carsales" => doTestcase!(carsales, args[2], args[3], args[4], iters),
        ~"catrank" => doTestcase!(catrank, args[2], args[3], args[4], iters),
        ~"eval" => doTestcase!(eval, args[2], args[3], args[4], iters),
        s => fail!("unrecognized test case: {}", s)
    }


}
{'fraction_non_alphanumeric': 0.14961861920594563, 'fraction_numerical': 0.008214355564247995, 'mean_word_length': 2.12019524100061, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2720898', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1523, 'n_words': 364}