glugify/performance

Types

Represents the results of a performance benchmark.

Contains timing information and operation counts for analyzing the performance characteristics of slugification operations.

pub type BenchmarkResult {
  BenchmarkResult(
    name: String,
    operations: Int,
    total_time_ms: Int,
    ops_per_second: Int,
    avg_time_per_op_microseconds: Int,
  )
}

Constructors

  • BenchmarkResult(
      name: String,
      operations: Int,
      total_time_ms: Int,
      ops_per_second: Int,
      avg_time_per_op_microseconds: Int,
    )

An optimized string builder that uses string trees for efficient concatenation.

This type wraps Gleam’s StringTree to provide an efficient way to build strings through multiple append operations without quadratic time complexity.

pub type OptimizedStringBuilder {
  OptimizedStringBuilder(tree: string_tree.StringTree)
}

Constructors

Values

pub fn append_to_builder(
  builder: OptimizedStringBuilder,
  text: String,
) -> OptimizedStringBuilder

Appends text to the string builder.

This operation is efficient and doesn’t require copying the entire string like regular string concatenation would.

Examples

new_string_builder()
|> append_to_builder("hello")
|> append_to_builder(" ")
|> append_to_builder("world")
pub fn benchmark_slugify(
  input: String,
  iterations: Int,
) -> BenchmarkResult

Benchmarks the simple slugify function with a given input.

Runs the slugification operation for the specified number of iterations and measures the total time, average time per operation, and operations per second.

Examples

let result = benchmark_slugify("Hello World", 1000)
// Measures performance of 1000 slugify operations
pub fn benchmark_slugify_with_config(
  input: String,
  config: config.Config,
  iterations: Int,
) -> BenchmarkResult

Benchmarks the slugify_with function with custom configuration.

Runs the slugification operation with the provided configuration for the specified number of iterations and measures performance.

Examples

let custom_config = config.default() |> config.with_separator("_")
let result = benchmark_slugify_with_config("Hello World", custom_config, 1000)
pub fn builder_to_string(
  builder: OptimizedStringBuilder,
) -> String

Converts the string builder to a final string.

This operation finalizes the string building process and returns the concatenated result as a regular string.

Examples

new_string_builder()
|> append_to_builder("hello")
|> append_to_builder(" world")
|> builder_to_string()
// -> "hello world"
pub fn new_string_builder() -> OptimizedStringBuilder

Creates a new empty string builder.

Examples

let builder = new_string_builder()
pub fn print_benchmark_result(result: BenchmarkResult) -> Nil

Prints a formatted benchmark result to the console.

Outputs operation count, total time, operations per second, and average time per operation in a readable format.

pub fn print_performance_report() -> Nil

Runs the complete performance suite and prints a formatted report.

This function executes all benchmarks and displays:

  • Individual benchmark results
  • Summary statistics
  • Total operations executed
  • Average operations per second across all tests
pub fn run_performance_suite() -> List(BenchmarkResult)

Runs a comprehensive performance benchmark suite.

Tests various input types and configurations:

  • Simple text
  • Unicode text with emojis
  • Long text (200+ characters)
  • Complex text with mixed case and symbols
  • Both default and custom configurations

Returns a list of benchmark results for analysis.

Search Document