<commit_before>static-regexp
=============

Very fast static regular expression using c++11 templates.

Usage
-----

	#include "regexp/regexp2.hpp"
	
	using namespace SRegExp2;
	
	// Equivalent to ^([a-z]+)
	RegularExpression<Begin, OneCatch<1, Plus<CSet<'a','z'>> > > regexp;
	
	if (regexp.match(string))
	{
		std::cout << "matched: " << regexp.part<1>(string) << "\n";
	}
	else std::cout << "string not matched!\n";
 
Benchmark
---------

Static regular expression is __19.5-times__ faster then libc++'s _<regex>_ implementation for simple pattern matching.

	$ time ./build/native/supergrep /tmp/somebigfile.txt > /dev/null
	
	real	0m20.654s
	user	0m18.842s
	sys	0m1.373s
	
While the normal libc++'s _<regexp>_ implementation is significantly slower for same pattern and file:
	
	$ time ./build/native/normalgrep /tmp/somebigfile.txt > /dev/null
	
	real	6m43.090s
	user	6m41.235s
	sys	0m1.544s

 
Example of generated code using clang 3.4
-----------------------------------------

	^[a-z]+://[a-z][a-z0-9]+(\.[a-z][a-z0-9]+)*/

will turn into:

	#include "regexp/regexp2.hpp"
	#include <cstdio>

	using namespace SRegExp2;

	int main (int argc, char const *argv[])
	{
		// you can combine sub-regexp into one
		using Protocol = Plus<CSet<'a','z'>>;
		using Domain = Seq<CSet<'a','z'>, Plus<CSet<'a','z','0','9'>>>;<commit_msg>Update of benchmark.<commit_after>static-regexp
=============

Very fast static regular expression using c++11 templates.

Usage
-----

	#include "regexp/regexp2.hpp"
	
	using namespace SRegExp2;
	
	// Equivalent to ^([a-z]+)
	RegularExpression<Begin, OneCatch<1, Plus<CSet<'a','z'>> > > regexp;
	
	if (regexp.match(string))
	{
		std::cout << "matched: " << regexp.part<1>(string) << "\n";
	}
	else std::cout << "string not matched!\n";
 
Benchmark
---------

Static regular expression is __19.5-times__ faster then libc++'s _<regex>_ implementation for simple pattern matching (ABCD).

	Str<'A','B','C','D'>

	$ time ./build/native/supergrep /tmp/somebigfile.txt > /dev/null
	
	real	0m20.654s
	user	0m18.842s
	sys	0m1.373s

While the normal libc++'s _<regexp>_ implementation is significantly slower for same pattern and file:

	$ time ./build/native/normalgrep /tmp/somebigfile.txt > /dev/null
	
	real	6m43.090s
	user	6m41.235s
	sys	0m1.544s

For more complex pattern (ABCDE|DEFGH|EFGHI|AAAA+) static regular expression maintain same speed:

	Selection<Str<'A','B','C','D','E'>,Str<'D','E','F','G','H'>,Str<'E','F','G','H','I'>,Repeat<4,0,Chr<'A'>>>

	real	0m21.647s
	user	0m20.579s
	sys	0m1.064s

And libc++'s _<regexp>_ is __3650-times__ slower!

	real	63m18.043s
	user	63m9.890s
	sys	0m4.731s
 
Example of generated code using clang 3.4
-----------------------------------------

	^[a-z]+://[a-z][a-z0-9]+(\.[a-z][a-z0-9]+)*/

will turn into:

	#include "regexp/regexp2.hpp"
	#include <cstdio>

	using namespace SRegExp2;

	int main (int argc, char const *argv[])
	{
		// you can combine sub-regexp into one
		using Protocol = Plus<CSet<'a','z'>>;
		using Domain = Seq<CSet<'a','z'>, Plus<CSet<'a','z','0','9'>>>;
{'fraction_non_alphanumeric': 0.21095800524934383, 'fraction_numerical': 0.04822834645669291, 'mean_word_length': 3.510355029585799, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 43, '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': '4240669', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1164, 'n_words': 273}