benches

package
v5.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

2MS Benchmarks

Build Tag Setup

These benchmarks are excluded from regular test runs using the //go:build bench build tag. This prevents the heavy benchmark setup (which creates 10,000 test files) from running during normal go test executions.

  • Regular tests: go test (benchmarks won't run)
  • Run benchmarks: Use the -tags=bench flag as shown below

Process Items Benchmark

This benchmark (BenchmarkProcessItems) tests the performance of secret detection processing across different configurations.

What it Tests
  1. Worker Pool Scaling

    • Tests different worker pool sizes based on CPU count
    • Ranges from half the CPU count up to 32x CPU count
    • Example for 8-core machine: tests 4, 8, 16, 32, 64, 128, and 256 workers
  2. Input Load Testing

    • Tests various input sizes: 50, 100, 500, 1000, and 10000 items
  3. Realistic Content

    • Simulates different file types:
      • JavaScript configurations
      • Python scripts
      • Shell scripts
      • YAML configurations
      • JSON configurations
    • Includes actual secret patterns:
      • GitHub Personal Access Tokens
      • API keys
      • JWTs
    • Varies file sizes (1KB, 10KB, 50KB)
    • Maintains a 60/40 ratio of files with/without secrets
Running the Benchmark
go test -tags=bench -timeout 0 -bench BenchmarkProcessItems -count 5 -run=^$
Command Flags Explained
  • -tags=bench: Enables compilation of benchmark code (required due to build tag)
  • -timeout 0: Disables test timeout (needed for long benchmarks)
  • -bench BenchmarkProcessItems: Runs only this specific benchmark
  • -count 5: Runs the benchmark 5 times for better statistical significance
  • -run=^$: Skips regular tests (only runs benchmarks)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContentTemplates = []string{

	`const config = {
  apiKey: '%s',
  endpoint: 'https://api.example.com',
  timeout: 5000,
  retries: 3,
  debug: process.env.NODE_ENV === 'development'
};

module.exports = config;`,

	`import requests
import os

API_KEY = '%s'
BASE_URL = 'https://api.service.com/v1'

def make_request(endpoint):
    headers = {
        'Authorization': f'Bearer {API_KEY}',
        'Content-Type': 'application/json'
    }
    return requests.get(f'{BASE_URL}/{endpoint}', headers=headers)

if __name__ == '__main__':
    response = make_request('users')
    print(response.json())`,

	`#!/bin/bash

# Configuration
export API_TOKEN='%s'
export SERVICE_URL="https://service.example.com"
export ENVIRONMENT="production"

# Function to call API
call_api() {
    curl -H "Authorization: Bearer $API_TOKEN" \
         -H "Content-Type: application/json" \
         "$SERVICE_URL/api/$1"
}

# Main execution
call_api "status"`,

	`apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  database_url: postgresql://user:pass@localhost/db
  api_key: %s
  redis_url: redis://localhost:6379
  log_level: info`,

	`{
  "name": "production-app",
  "version": "1.0.0",
  "config": {
    "api": {
      "key": "%s",
      "endpoint": "https://api.production.com",
      "timeout": 30000
    },
    "database": {
      "host": "db.production.com",
      "port": 5432
    }
  }
}`,

	`package utils

import (
    "fmt"
    "strings"
    "time"
)

func ProcessData(input string) (string, error) {
    if input == "" {
        return "", fmt.Errorf("input cannot be empty")
    }
    
    processed := strings.ToUpper(input)
    timestamp := time.Now().Format(time.RFC3339)
    
    return fmt.Sprintf("%s - %s", processed, timestamp), nil
}

func ValidateInput(data []byte) bool {
    return len(data) > 0 && len(data) < 1048576
}`,
}

ContentTemplates contains realistic file content templates simulating different file types Templates 0-4 contain secrets, template 5 is clean code

View Source
var FileExtensions = []string{
	".js",
	".py",
	".sh",
	".yml",
	".json",
	".go",
}

FileExtensions maps content template indices to appropriate file extensions

View Source
var PaddingPatterns = []string{
	"\n\n// Helper functions\n",
	"function helper() { return true; }\n",
	"const data = { id: 1, name: 'test' };\n",
	"if (condition) { console.log('debug'); }\n",
	"// TODO: refactor this later\n",
	"/* eslint-disable no-unused-vars */\n",
	"import { util } from './utils';\n",
	"export default class Component {}\n",
}

PaddingPatterns contains common code patterns used for generating realistic file padding

View Source
var SecretPatterns = []string{
	"github_pat_11ABCDEFG1234567890abcdefghijklmnopqrstuvwxyz123456",
	"sk-1234567890abcdefghijklmnopqrstuvwxyz",
	"ghp_abcdefghijklmnopqrstuvwxyz1234567890",
	"AIzaSyC1234567890abcdefghijklmnopqrstuv",
	"xoxb-123456789012-1234567890123-abcdefghijklmnopqrstuvwx",
	"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
}

SecretPatterns contains realistic secret patterns that will trigger detection

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL