From f688501392d419a5299d8606d150080222662fc4 Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Tue, 31 Jan 2023 09:57:16 +0100 Subject: [PATCH] test: add benchmark focussed on idCode (#153) * test: add benchmark focussed on idCode * chore: improve benchmark --- benchmark/diastereoID.js | 24 ++++++++++++++++++++++++ benchmark/wikipedia.js | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 benchmark/diastereoID.js create mode 100644 benchmark/wikipedia.js diff --git a/benchmark/diastereoID.js b/benchmark/diastereoID.js new file mode 100644 index 00000000..caed2473 --- /dev/null +++ b/benchmark/diastereoID.js @@ -0,0 +1,24 @@ +'use strict'; + +const { getDiastereotopicAtomIDs } = require('openchemlib-utils'); + +const { Molecule, version } = require('../dist/openchemlib-full'); + +async function doAll() { + console.log('OCL version', version); + console.time('diastereoID'); + const response = await fetch( + 'https://wikipedia.cheminfo.org/src/json/data.json', + ); + const entries = (await response.json()).data.molecules; + let totalLength = 0; + for (const entry of entries.slice(0, 700)) { + const molecule = Molecule.fromIDCode(entry.actID.value); + const ids = getDiastereotopicAtomIDs(molecule); + totalLength += ids.length; + } + console.timeEnd('diastereoID'); + console.log(totalLength); +} + +doAll(); diff --git a/benchmark/wikipedia.js b/benchmark/wikipedia.js new file mode 100644 index 00000000..07beec67 --- /dev/null +++ b/benchmark/wikipedia.js @@ -0,0 +1,22 @@ +'use strict'; + +const { Molecule, version } = require('../dist/openchemlib-full'); + +async function doAll() { + console.log('OCL version', version); + console.time('wikipedia'); + const response = await fetch( + 'https://wikipedia.cheminfo.org/src/json/data.json', + ); + const entries = (await response.json()).data.molecules; + const idCodes = []; + for (const entry of entries.slice(0, 10000)) { + const molecule = Molecule.fromIDCode(entry.actID.value); + const idCode = molecule.getIDCode(); + idCodes.push(idCode); + } + console.timeEnd('wikipedia'); + console.log(idCodes.join(',').length); +} + +doAll();