-
Notifications
You must be signed in to change notification settings - Fork 1
feat: recursive json object test #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6770506
feat: recursive json object test
samuelscheit 55e557c
feat: go and python example
samuelscheit 72e336c
perf: use string builder
samuelscheit 7646643
perf: use string builder
samuelscheit 3e75307
chore: remove go and js recursion test + merge in gen.py
samuelscheit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`); | ||
| } |
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove this please