Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/recursion.go

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove this please

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strings"
)

var depths = map[string]int{
"1K": 1000,
"10K": 10000,
"100K": 100000,
"1M": 1000000,
"10M": 10000000,
}

func main() {
for depthName, depth := range depths {
fmt.Printf("Generating %d depth object\n", depth)

var builder strings.Builder
builder.WriteString("{")

for i := 1; i < depth; i++ {
builder.WriteString(`"next":{`)
}

builder.WriteString(`"next":null`)

for i := 0; i < depth; i++ {
builder.WriteString("}")
}

jsonString := builder.String()

fileName := fmt.Sprintf("%s_recursion.json", depthName)
filePath := filepath.Join(filepath.Dir(os.Args[0]), fileName)

err := os.WriteFile(filePath, []byte(jsonString), 0644)
if err != nil {
fmt.Printf("Error writing file: %v\n", err)
continue
}

fmt.Printf("File for depth %d saved as %s\n", depth, fileName)
}
}
31 changes: 31 additions & 0 deletions test/recursion.js

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require("fs");

const depths = {
"1K": 1_000,
"10K": 10_000,
"100K": 100_000,
"1M": 1_000_000,
"10M": 10_000_000,
};

for (let depthName in depths) {
const depth = depths[depthName];
console.log(`Generating ${depth} depth object`);

let jsonString = "{";

for (let i = 1; i < depth; i++) {
jsonString += '"next":{';
}

jsonString += '"next":null';

for (let i = 0; i < depth; i++) {
jsonString += "}";
}

const fileName = `${depthName}_recursion.json`;

fs.writeFileSync(__dirname + `/${fileName}`, jsonString);
console.log(`File for depth ${depth} saved as ${fileName}`);
}
32 changes: 32 additions & 0 deletions test/recursion.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this file with test/gen.py and add hyperfine calls for each of the depths, as seen in test/bench.sh

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

depths = {
"1K": 1_000,
"10K": 10_000,
"100K": 100_000,
"1M": 1_000_000,
"10M": 10_000_000,
}

for depth_name, depth in depths.items():
print(f"Generating {depth} depth object")

json_parts = ["{"]

for _ in range(1, depth):
json_parts.append('"next":{')

json_parts.append('"next":null')

for _ in range(depth):
json_parts.append("}")

json_string = "".join(json_parts)

file_name = f"{depth_name}_recursion.json"
file_path = os.path.join(os.path.dirname(__file__), file_name)

with open(file_path, 'w') as f:
f.write(json_string)

print(f"File for depth {depth} saved as {file_name}")