From dcb90ad1769b55952ba6bc829c5e740b5b5fa9ba Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Fri, 17 Oct 2014 18:07:01 -0400 Subject: [PATCH] added benchmark for tokenizing English text --- analysis/tokenizers/icu/boundary_test.go | 18 ++++++++++++++++++ .../whitespace_tokenizer_test.go | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/analysis/tokenizers/icu/boundary_test.go b/analysis/tokenizers/icu/boundary_test.go index 8c0c762a..65c0db52 100644 --- a/analysis/tokenizers/icu/boundary_test.go +++ b/analysis/tokenizers/icu/boundary_test.go @@ -171,3 +171,21 @@ func TestBoundary(t *testing.T) { } } } + +var sampleLargeInput = []byte(`There are three characteristics of liquids which are relevant to the discussion of a BLEVE: +If a liquid in a sealed container is boiled, the pressure inside the container increases. As the liquid changes to a gas it expands - this expansion in a vented container would cause the gas and liquid to take up more space. In a sealed container the gas and liquid are not able to take up more space and so the pressure rises. Pressurized vessels containing liquids can reach an equilibrium where the liquid stops boiling and the pressure stops rising. This occurs when no more heat is being added to the system (either because it has reached ambient temperature or has had a heat source removed). +The boiling temperature of a liquid is dependent on pressure - high pressures will yield high boiling temperatures, and low pressures will yield low boiling temperatures. A common simple experiment is to place a cup of water in a vacuum chamber, and then reduce the pressure in the chamber until the water boils. By reducing the pressure the water will boil even at room temperature. This works both ways - if the pressure is increased beyond normal atmospheric pressures, the boiling of hot water could be suppressed far beyond normal temperatures. The cooling system of a modern internal combustion engine is a real-world example. +When a liquid boils it turns into a gas. The resulting gas takes up far more space than the liquid did. +Typically, a BLEVE starts with a container of liquid which is held above its normal, atmospheric-pressure boiling temperature. Many substances normally stored as liquids, such as CO2, oxygen, and other similar industrial gases have boiling temperatures, at atmospheric pressure, far below room temperature. In the case of water, a BLEVE could occur if a pressurized chamber of water is heated far beyond the standard 100 °C (212 °F). That container, because the boiling water pressurizes it, is capable of holding liquid water at very high temperatures. +If the pressurized vessel, containing liquid at high temperature (which may be room temperature, depending on the substance) ruptures, the pressure which prevents the liquid from boiling is lost. If the rupture is catastrophic, where the vessel is immediately incapable of holding any pressure at all, then there suddenly exists a large mass of liquid which is at very high temperature and very low pressure. This causes the entire volume of liquid to instantaneously boil, which in turn causes an extremely rapid expansion. Depending on temperatures, pressures and the substance involved, that expansion may be so rapid that it can be classified as an explosion, fully capable of inflicting severe damage on its surroundings.`) + +func BenchmarkTokenizeEnglishText(b *testing.B) { + + tokenizer := NewUnicodeWordBoundaryCustomLocaleTokenizer("en_US") + b.ResetTimer() + + for i := 0; i < b.N; i++ { + tokenizer.Tokenize(sampleLargeInput) + } + +} diff --git a/analysis/tokenizers/whitespace_tokenizer/whitespace_tokenizer_test.go b/analysis/tokenizers/whitespace_tokenizer/whitespace_tokenizer_test.go index 054bb73b..2ae1787d 100644 --- a/analysis/tokenizers/whitespace_tokenizer/whitespace_tokenizer_test.go +++ b/analysis/tokenizers/whitespace_tokenizer/whitespace_tokenizer_test.go @@ -130,3 +130,21 @@ func TestBoundary(t *testing.T) { } } } + +var sampleLargeInput = []byte(`There are three characteristics of liquids which are relevant to the discussion of a BLEVE: +If a liquid in a sealed container is boiled, the pressure inside the container increases. As the liquid changes to a gas it expands - this expansion in a vented container would cause the gas and liquid to take up more space. In a sealed container the gas and liquid are not able to take up more space and so the pressure rises. Pressurized vessels containing liquids can reach an equilibrium where the liquid stops boiling and the pressure stops rising. This occurs when no more heat is being added to the system (either because it has reached ambient temperature or has had a heat source removed). +The boiling temperature of a liquid is dependent on pressure - high pressures will yield high boiling temperatures, and low pressures will yield low boiling temperatures. A common simple experiment is to place a cup of water in a vacuum chamber, and then reduce the pressure in the chamber until the water boils. By reducing the pressure the water will boil even at room temperature. This works both ways - if the pressure is increased beyond normal atmospheric pressures, the boiling of hot water could be suppressed far beyond normal temperatures. The cooling system of a modern internal combustion engine is a real-world example. +When a liquid boils it turns into a gas. The resulting gas takes up far more space than the liquid did. +Typically, a BLEVE starts with a container of liquid which is held above its normal, atmospheric-pressure boiling temperature. Many substances normally stored as liquids, such as CO2, oxygen, and other similar industrial gases have boiling temperatures, at atmospheric pressure, far below room temperature. In the case of water, a BLEVE could occur if a pressurized chamber of water is heated far beyond the standard 100 °C (212 °F). That container, because the boiling water pressurizes it, is capable of holding liquid water at very high temperatures. +If the pressurized vessel, containing liquid at high temperature (which may be room temperature, depending on the substance) ruptures, the pressure which prevents the liquid from boiling is lost. If the rupture is catastrophic, where the vessel is immediately incapable of holding any pressure at all, then there suddenly exists a large mass of liquid which is at very high temperature and very low pressure. This causes the entire volume of liquid to instantaneously boil, which in turn causes an extremely rapid expansion. Depending on temperatures, pressures and the substance involved, that expansion may be so rapid that it can be classified as an explosion, fully capable of inflicting severe damage on its surroundings.`) + +func BenchmarkTokenizeEnglishText(b *testing.B) { + + tokenizer := regexp_tokenizer.NewRegexpTokenizer(whitespaceTokenizerRegexp) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + tokenizer.Tokenize(sampleLargeInput) + } + +}