Skip to content

Commit

Permalink
Merge pull request #56 from tscircuit/benchmark
Browse files Browse the repository at this point in the history
Benchmark
  • Loading branch information
seveibar authored Oct 12, 2024
2 parents f7ecd2b + 0ed38e2 commit ca7e719
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
*.bettereasy.json
.vscode
tmp
temp.tsx
48 changes: 48 additions & 0 deletions benchmark/benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { readFile, writeFile } from "node:fs/promises"
import { convertEasyEdaJsonToVariousFormats } from "../lib/convert-easyeda-json-to-various-formats"
import path from "node:path"

async function benchmark() {
const partnumbersPath = path.join(__dirname, "partnumbers.json")
const resultPath = path.join(__dirname, "result.txt")

let partnumbers: string[]
try {
const data = await readFile(partnumbersPath, "utf-8")
partnumbers = JSON.parse(data)
} catch (error) {
console.error("Error reading partnumbers.json:", error)
return
}

let successes = 0
let failures = 0
let failureLog = ""

for (const partnumber of partnumbers) {
try {
await convertEasyEdaJsonToVariousFormats({
jlcpcbPartNumberOrFilepath: partnumber,
outputFilename: "temp.tsx",
formatType: "tsx",
})
successes++
} catch (error) {
failures++
failureLog += `Part number: ${partnumber}\nError: ${error}\n\n`
}
}

const summary = `Successes: ${successes}\nFailures: ${failures}\n\nFailure Details:\n${failureLog}`

try {
await writeFile(resultPath, summary)
console.log(`Benchmark complete. Results written to ${resultPath}`)
console.log(`Successes: ${successes}`)
console.log(`Failures: ${failures}`)
} catch (error) {
console.error("Error writing result.txt:", error)
}
}

benchmark()
26 changes: 26 additions & 0 deletions benchmark/partnumbers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
"C21376",
"C25744",
"C965808",
"C14663",
"C1178474",
"C1153543",
"C1177579",
"C1184469",
"C1185108",
"C1180645",
"C1189664",
"C1178711",
"C389354",
"C516304",
"C2998002",
"C74384",
"C11702",
"C94784",
"C72044",
"C49678",
"C25804",
"C26083",
"C2843864",
"C2040"
]
43 changes: 43 additions & 0 deletions benchmark/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Successes: 11
Failures: 13

Failure Details:
Part number: C965808
Error: Error: Invalid shape type: PT~M 245 303 L 235 310 L 245 317 Z ~#880000~1~0~none~gge49~0~

Part number: C1178474
Error: Error: Component not found

Part number: C1153543
Error: Error: Component not found

Part number: C1177579
Error: Error: Component not found

Part number: C1184469
Error: Error: Component not found

Part number: C1185108
Error: Error: Component not found

Part number: C1180645
Error: Error: Component not found

Part number: C1189664
Error: Error: Component not found

Part number: C1178711
Error: Error: Component not found

Part number: C389354
Error: Error: Invalid shape type: PT~M 405 294 L 395 300 L 405 307 Z ~#880000~1~0~none~gge18~0~

Part number: C516304
Error: Error: Invalid shape type: PT~M 395 326 L 405 320 L 395 313 Z~#880000~1~0~#880000~gge25~0~

Part number: C2998002
Error: Error: Invalid shape type: T~L~415~303~0~#0000FF~~5.5pt~~~~comment~TR1~1~start~gge7~0~pinpart

Part number: C2843864
Error: Error: Invalid shape type: PT~M 420 337 L 430 330 L 420 323 Z ~#880000~1~0~none~gge82~0~

18 changes: 14 additions & 4 deletions lib/convert-easyeda-json-to-various-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,36 @@ export const convertEasyEdaJsonToVariousFormats = async ({
const betterEasy = EasyEdaJsonSchema.parse(rawEasyEdaJson)
const tscircuitSoup = convertEasyEdaJsonToTscircuitSoupJson(betterEasy)

if (outputFilename.endsWith(".soup.json")) {
if (
outputFilename.endsWith(".soup.json") ||
outputFilename.endsWith(".circuit.json")
) {
await fs.writeFile(outputFilename, JSON.stringify(tscircuitSoup, null, 2))
console.log(`Converted to tscircuit soup JSON: ${outputFilename}`)
console.log(
`[${jlcpcbPartNumberOrFilepath}] Converted to circuit json: ${outputFilename}`,
)
} else if (outputFilename.endsWith(".kicad_mod")) {
// TODO: Implement conversion to KiCad footprint
console.log("Conversion to KiCad footprint not yet implemented")
} else if (outputFilename.endsWith(".bettereasy.json")) {
await fs.writeFile(outputFilename, JSON.stringify(betterEasy, null, 2))
console.log(`Saved better EasyEDA JSON: ${outputFilename}`)
console.log(
`[${jlcpcbPartNumberOrFilepath}] Saved better EasyEDA JSON: ${outputFilename}`,
)
} else if (
outputFilename.endsWith(".tsx") ||
outputFilename.endsWith(".ts")
) {
const tsComp = await convertRawEasyEdaToTs(rawEasyEdaJson)
await fs.writeFile(outputFilename, tsComp)
console.log(`Saved TypeScript component: ${outputFilename}`)
console.log(
`[${jlcpcbPartNumberOrFilepath}] Saved TypeScript component: ${outputFilename}`,
)
} else {
console.error("Unsupported output format")
}
} catch (error: any) {
console.error("Error:", error.message)
throw error
}
}

0 comments on commit ca7e719

Please sign in to comment.