Compare commits
1 commit
main
...
badmessage
Author | SHA1 | Date | |
---|---|---|---|
|
b7415d18eb |
8 changed files with 115 additions and 0 deletions
|
@ -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
6
rust/badmessage/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
node_modules
|
||||||
|
yarn.lock
|
||||||
|
flamegraph.svg
|
||||||
|
/prof
|
18
rust/badmessage/Cargo.toml
Normal file
18
rust/badmessage/Cargo.toml
Normal 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
|
||||||
|
|
26
rust/badmessage/automerge-js.js
Normal file
26
rust/badmessage/automerge-js.js
Normal 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`)
|
26
rust/badmessage/automerge-wasm.js
Normal file
26
rust/badmessage/automerge-wasm.js
Normal 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
BIN
rust/badmessage/badmessage
Executable file
Binary file not shown.
13
rust/badmessage/package.json
Normal file
13
rust/badmessage/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
25
rust/badmessage/src/main.rs
Normal file
25
rust/badmessage/src/main.rs
Normal 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(())
|
||||||
|
}
|
Loading…
Reference in a new issue