diff --git a/README.md b/README.md index 318f050..98432d4 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ cargo install dust-lang dust ``` +## Benchmarks + ## Development Status Currently, Dust is being prepared for version 1.0. Until then, there may be breaking changes to the language and CLI. diff --git a/scripts/bench.fish b/scripts/bench.fish index f32fd10..6db5f1a 100755 --- a/scripts/bench.fish +++ b/scripts/bench.fish @@ -11,7 +11,7 @@ hyperfine \ --shell none \ --parameter-list data_path examples/assets/seaCreatures.json \ --warmup 3 \ - "dust -c 'length(json:parse(fs:read_file(\"{data_path}\")))'" \ + "target/release/dust -c 'length(json:parse(fs:read_file(\"{data_path}\")))'" \ "jq 'length' {data_path}" \ "node --eval \"require('node:fs').readFile('{data_path}', (err, data)=>{console.log(JSON.parse(data).length)})\"" \ "nu -c 'open {data_path} | length'" @@ -20,7 +20,7 @@ hyperfine \ --shell none \ --parameter-list data_path examples/assets/jq_data.json \ --warmup 3 \ - "dust -c 'length(json:parse(fs:read_file(\"{data_path}\")))'" \ + "target/release/dust -c 'length(json:parse(fs:read_file(\"{data_path}\")))'" \ "jq 'length' {data_path}" \ "node --eval \"require('node:fs').readFile('{data_path}', (err, data)=>{console.log(JSON.parse(data).length)})\"" \ "nu -c 'open {data_path} | length'" @@ -29,7 +29,7 @@ hyperfine \ --shell none \ --parameter-list data_path dielectron.json \ --warmup 3 \ - "dust -c 'length(json:parse(fs:read_file(\"{data_path}\")))'" \ + "target/release/dust -c 'length(json:parse(fs:read_file(\"{data_path}\")))'" \ "jq 'length' {data_path}" \ "node --eval \"require('node:fs').readFile('{data_path}', (err, data)=>{console.log(JSON.parse(data).length)})\"" \ "nu -c 'open {data_path} | length'" diff --git a/src/built_in_functions/fs.rs b/src/built_in_functions/fs.rs index 38a0847..279bc97 100644 --- a/src/built_in_functions/fs.rs +++ b/src/built_in_functions/fs.rs @@ -1,4 +1,4 @@ -use std::fs::read_to_string; +use std::{fs::File, io::Read}; use enum_iterator::{all, Sequence}; use serde::{Deserialize, Serialize}; @@ -46,7 +46,11 @@ impl Callable for Fs { RuntimeError::expect_argument_amount(self.name(), 1, arguments.len())?; let path = arguments.first().unwrap().as_string()?; - let file_content = read_to_string(path.as_str())?; + let mut file = File::open(path)?; + let file_size = file.metadata()?.len() as usize; + let mut file_content = String::with_capacity(file_size); + + file.read_to_string(&mut file_content)?; Ok(Value::string(file_content)) }