Compare commits

...

1 commit

Author SHA1 Message Date
Orion Henry
b7415d18eb adding a badmessage performance case 2022-12-09 18:01:57 -06:00
8 changed files with 115 additions and 0 deletions

View file

@ -6,6 +6,7 @@ members = [
"automerge-test", "automerge-test",
"automerge-wasm", "automerge-wasm",
"edit-trace", "edit-trace",
"badmessage",
] ]
resolver = "2" resolver = "2"

6
rust/badmessage/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
/target
Cargo.lock
node_modules
yarn.lock
flamegraph.svg
/prof

View file

@ -0,0 +1,18 @@
[package]
name = "badmessage"
version = "0.1.0"
edition = "2021"
license = "MIT"
[dependencies]
automerge = { path = "../automerge" }
criterion = "0.3.5"
json = "0.12.4"
rand = "^0.8"
[[bin]]
name = "badmessage"
doc = false
bench = false

View file

@ -0,0 +1,26 @@
// Apply the paper editing trace to an Automerge.Text object, one char at a time
const Automerge = require('../../javascript')
const fs = require('fs');
const start = new Date()
let contents = fs.readFileSync("badmessage");
let doc = Automerge.init();
let state = Automerge.initSyncState();
[doc,state] = Automerge.receiveSyncMessage(doc, state, contents);
console.log(`doc.receiveSyncMessage in ${new Date() - start} ms`)
let t_time = new Date()
let saved = Automerge.save(doc);
console.log(`doc.save in ${new Date() - t_time} ms`)
t_time = new Date()
Automerge.load(saved)
console.log(`doc.load in ${new Date() - t_time} ms`)
t_time = new Date()
let doc2 = Automerge.init()
doc2 = Automerge.loadIncremental(doc2,saved)
console.log(`doc.loadIncremental in ${new Date() - t_time} ms`)

View file

@ -0,0 +1,26 @@
const Automerge = require('../automerge-wasm')
const fs = require('fs');
let contents = fs.readFileSync("badmessage");
let doc = Automerge.create();
let state = Automerge.initSyncState();
let t_time = new Date()
doc.receiveSyncMessage(state,contents);
console.log(`doc.receiveSyncMessage in ${new Date() - t_time} ms`)
t_time = new Date()
let saved = doc.save()
console.log(`doc.save in ${new Date() - t_time} ms`)
t_time = new Date()
Automerge.load(saved)
console.log(`doc.load in ${new Date() - t_time} ms`)
t_time = new Date()
let doc2 = Automerge.create()
doc2.loadIncremental(saved)
console.log(`doc.loadIncremental in ${new Date() - t_time} ms`)

BIN
rust/badmessage/badmessage Executable file

Binary file not shown.

View file

@ -0,0 +1,13 @@
{
"name": "badmessage",
"version": "1.0.0",
"main": "wasm-text.js",
"license": "MIT",
"scripts": {
"wasm": "0x -D prof automerge-wasm.js",
"js": "0x -D prof automerge-js.js"
},
"devDependencies": {
"0x": "^5.4.1"
}
}

View file

@ -0,0 +1,25 @@
use automerge::sync;
use automerge::{Automerge, AutomergeError};
use std::fs;
use std::time::Instant;
fn main() -> Result<(), AutomergeError> {
let contents = fs::read("badmessage").expect("cant read badmessage file");
let mut doc = Automerge::new();
let mut state = sync::State::new();
let now = Instant::now();
// decode and receive happen at the same time in wasm so lets keep it apples to apples
let message = sync::Message::decode(contents.as_slice()).expect("cant decode message");
doc.receive_sync_message(&mut state, message).unwrap();
println!("decode/receive in {} ms", now.elapsed().as_millis());
let now = Instant::now();
let saved = doc.save();
println!("save in {} ms", now.elapsed().as_millis());
let now = Instant::now();
let _ = Automerge::load(&saved).unwrap();
println!("load in {} ms", now.elapsed().as_millis());
let mut doc2 = Automerge::new();
doc2.load_incremental(saved.as_slice()).unwrap();
println!("load_incremental in {} ms", now.elapsed().as_millis());
Ok(())
}