5

Native Messaging JavaScript runtime tests

 1 year ago
source link: https://gist.github.com/guest271314/fb8969a956a873e495b890a42ac0d731
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Native Messaging JavaScript runtime tests · GitHub

Instantly share code, notes, and snippets.

Native Messaging JavaScript runtime tests

Native Messaging JavaScript runtime hosts tested:

  • QuickJS
  • Node.js

Test: Send new Array(10000) from client to host, send message back to client, 100 times, measure time with performance.now().

native_messaging_javascript_runtime_tests_4.json sends 1MB (new Array(209715)) from client to host, host to client.

(async()=>{
  let hosts = {
    'nm_quickjs': [],
    'nm_deno': [],
    'nm_nodejs': [],
    'nm_bun': []
  };
  for (let i = 0; i < 100; i++) {
    for (const [hostName,data] of Object.entries(hosts)) {
      await new Promise((resolve)=>{
        let now = performance.now();
        var port = chrome.runtime.connectNative(hostName);
        port.onMessage.addListener(e=>{
          hosts[hostName].push((performance.now() - now) / 1000);
          port.disconnect();
          resolve();
        }
        );
        port.onDisconnect.addListener(e=>console.log(e));
        port.postMessage(new Array(10000));
      }
      )
    }
  }
  return hosts;
}
)().then(async(data)=>{
  const json = JSON.stringify(data, null, 2);
  console.log(data);
  onclick = async()=>{
    onclick = null;
    try {
      let fs = await showSaveFilePicker({
        suggestedName: 'native_messaging_javascript_runtime_tests_1.json'
      });
      let writable = await fs.createWritable();
      await new Blob([json],{
        type: 'application/json'
      }).stream().pipeTo(writable);
    } catch (err) {
      console.log(err);
    }
  }
}
, console.error);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK