-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ratel-rust/test-n-benches
No Rust CLI, added benchmarks
- Loading branch information
Showing
8 changed files
with
159 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
[package] | ||
name = "ratel" | ||
version = "0.3.0" | ||
version = "0.4.0" | ||
authors = ["Maciej Hirsz <[email protected]>"] | ||
license = "MIT" | ||
description = "JavaScript transpiler in Rust" | ||
repository = "https://github.com/ratel-rust/ratel-core" | ||
documentation = "https://github.com/ratel-rust/ratel-core" | ||
|
||
[profile.release] | ||
panic = "abort" | ||
|
||
[dependencies] | ||
docopt = "0.6.78" | ||
rustc-serialize = "0.3.16" | ||
itoa = "0.1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# the `ratel` crate | ||
|
||
## Test: | ||
|
||
``` | ||
cargo test | ||
``` | ||
|
||
## Benchmark: | ||
|
||
``` | ||
cargo bench | ||
``` | ||
|
||
Benchmarks require a nightly version of Rust to work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
extern crate ratel; | ||
|
||
use test::Bencher; | ||
|
||
static SOURCE: &'static str = r#" | ||
'use strict'; | ||
/** | ||
* Extranct red color out of a color integer: | ||
* | ||
* 0x00DEAD -> 0x00 | ||
* | ||
* @param {Number} color | ||
* @return {Number} | ||
*/ | ||
function red( color ) | ||
{ | ||
let foo = 3.14; | ||
return color >> 16; | ||
} | ||
/** | ||
* Extranct red color out of a color integer: | ||
* | ||
* 0x00DEAD -> 0xDE | ||
* | ||
* @param {Number} color | ||
* @return {Number} | ||
*/ | ||
function green( color ) | ||
{ | ||
return ( color >> 8 ) & 0xFF; | ||
} | ||
/** | ||
* Extranct red color out of a color integer: | ||
* | ||
* 0x00DEAD -> 0xAD | ||
* | ||
* @param {Number} color | ||
* @return {Number} | ||
*/ | ||
function blue( color ) | ||
{ | ||
return color & 0xFF; | ||
} | ||
/** | ||
* Converts an integer containing a color such as 0x00DEAD to a hex | ||
* string, such as '#00DEAD'; | ||
* | ||
* @param {Number} int | ||
* @return {String} | ||
*/ | ||
function intToHex( int ) | ||
{ | ||
const mask = '#000000'; | ||
const hex = int.toString( 16 ); | ||
return mask.substring( 0, 7 - hex.length ) + hex; | ||
} | ||
/** | ||
* Converts a hex string containing a color such as '#00DEAD' to | ||
* an integer, such as 0x00DEAD; | ||
* | ||
* @param {Number} num | ||
* @return {String} | ||
*/ | ||
function hexToInt( hex ) | ||
{ | ||
return parseInt( hex.substring( 1 ), 16 ); | ||
} | ||
module.exports = { | ||
red, | ||
green, | ||
blue, | ||
intToHex, | ||
hexToInt, | ||
}; | ||
"#; | ||
|
||
#[bench] | ||
fn parse_to_ast(b: &mut Bencher) { | ||
b.bytes = SOURCE.len() as u64; | ||
|
||
b.iter(|| { | ||
let ast = ratel::parser::parse(SOURCE.to_owned()).expect("Must parse"); | ||
|
||
ast | ||
}); | ||
} | ||
|
||
|
||
#[bench] | ||
fn parse_to_ast_and_transform_es5(b: &mut Bencher) { | ||
b.bytes = SOURCE.len() as u64; | ||
|
||
b.iter(|| { | ||
let mut ast = ratel::parser::parse(SOURCE.to_owned()).expect("Must parse"); | ||
|
||
let settings = ratel::transformer::Settings::target_es5(); | ||
|
||
ratel::transformer::transform(&mut ast, settings); | ||
|
||
ast | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn codegen_from_ast(b: &mut Bencher) { | ||
let mut ast = ratel::parser::parse(SOURCE.to_owned()).expect("Must parse"); | ||
|
||
let settings = ratel::transformer::Settings::target_es5(); | ||
|
||
ratel::transformer::transform(&mut ast, settings); | ||
|
||
let output = ratel::codegen::generate_code(&ast, true); | ||
|
||
b.bytes = output.len() as u64; | ||
|
||
b.iter(|| { | ||
ratel::codegen::generate_code(&ast, true) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
npm-debug.log | ||
Cargo.lock | ||
native/target | ||
native/index.node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters