<commit_before>#![feature(test)]
#![allow(unused_imports)]
#![allow(dead_code)]

extern crate test;

#[macro_use]
extern crate teleport;

use std::fmt::Write;
use std::mem::replace;
use test::Bencher;
use std::iter::{repeat, FromIterator, IntoIterator};


use teleport::{push_attribute, AttributeValue, Attribute};



#[bench]
fn string_concat(b: &mut Bencher) {

   let mut table_contents: Vec<Vec<u32>> = Vec::new();
   //let mut table_contents: Vec<[u32; 10]> = Vec::new();
   for i in 0..10000 {
      let k = i*10;
      table_contents.push(Vec::from_iter((k..k+10)))
      //table_contents.push([k, k+1, k+2, k+3, k+4, k+5, k+6, k+7, k+8, k+9]);
   }

   b.iter(|| {
      let mut result = String::new();
      result.push_str("<table>\n");

      for index in 0..10000 {//table_contents.iter() {
         result.push_str("  <tr>\n");

         for item in table_contents[index].iter() {
            result.push_str("    <td>");
            result.push_str(&item.to_string());
            result.push_str("<td>\n");
         }

         result.push_str("  </tr>\n");
      }

      result.push_str("</table>");
   });
}


pub fn main() {
   let class = AttributeValue::List(vec![
      AttributeValue::StaticString("first"),
      AttributeValue::StaticString("second")
   ]);

   let first_attr = Attribute {
      name: "class",
      value: class,
   };

   let mut rendered = String::new();

   push_attribute(&first_attr, &mut rendered);

   println!("{}", rendered);

   let list = attr!["id", "location"; "class", "identical"];

   println!("{:?}", list);
}<commit_msg>More template speed benchmarking.<commit_after>#![feature(test)]
#![allow(unused_imports)]
#![allow(dead_code)]

extern crate test;

#[macro_use]
extern crate teleport;

use std::fmt::Write;
use std::mem::replace;
use test::Bencher;
use std::iter::{repeat, FromIterator, IntoIterator};


use teleport::{push_attribute, AttributeValue, Attribute};


#[bench]
fn concat_string_source(b: &mut Bencher) {
   let mut table_contents: Vec<[&'static str; 10]> = Vec::new();
   for _ in 0..1000 {
      table_contents.push(["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj"])
   }

   b.iter(|| {
      let mut result = String::with_capacity(200000);
      result.push_str("<table>\n");

      for row in table_contents.iter() {
         result.push_str("  <tr>\n");

         for item in row {
            result.push_str("    <td>");
            result.push_str(&item.to_string());
            result.push_str("<td>\n");
         }

         result.push_str("  </tr>\n");
      }

      result.push_str("</table>");

      result
   });
}


#[bench]
fn concat_vector_source(b: &mut Bencher) {
   let mut table_contents: Vec<[&'static str; 10]> = Vec::new();
   for _ in 0..1000 {
      table_contents.push(["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj"])
   }

   b.iter(|| {
      let mut result = Vec::new();
      result.push("<table>\n");

      for row in table_contents.iter() {
         result.push("  <tr>\n");

         for item in row {
            result.push("    <td>");
            result.push(item);
            result.push("<td>\n");
         }

         result.push("  </tr>\n");
      }

      result.push("</table>");
   });
}


fn render_table() {
   let mut table_contents: Vec<[&'static str; 10]> = Vec::new();
   for _ in 0..1000 {
      table_contents.push(["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj"])
   }

   let mut result = Vec::with_capacity(36000);
   result.push("<table>\n");

   for row in table_contents.iter() {
      result.push("  <tr>\n");

      for item in row {
         result.push("    <td>");
         result.push(item);
         result.push("<td>\n");
      }

      result.push("  </tr>\n");
   }

   result.push("</table>");

   println!("{}", result.len())
}


pub fn main() {
   render_table();

   // let class = AttributeValue::List(vec![
   //    AttributeValue::StaticString("first"),
   //    AttributeValue::StaticString("second")
   // ]);
   //
   // let first_attr = Attribute {
   //    name: "class",
   //    value: class,
   // };
   //
   // let mut rendered = String::new();
   //
   // push_attribute(&first_attr, &mut rendered);
   //
   // println!("{}", rendered);
   //
   // let list = attr!["id", "location"; "class", "identical"];
   //
   // println!("{:?}", list);
}
{'fraction_non_alphanumeric': 0.2099219108865411, 'fraction_numerical': 0.014469453376205787, 'mean_word_length': 2.6321934945788157, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178718', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1504, 'n_words': 317}