When executing Python natively:
$ python pystone.py
Pystone(1.1) time for 50000 passes = 0.129016
This machine benchmarks at 387549 pystones/second
curl https://registry-cdn.wapm.io/contents/_/clang/0.1.0/clang.wasm -O clang.wasm | |
# Install Wasmer 0.17.1 | |
curl https://get.wasmer.io -sSfL | WASMER_DIR=`pwd`/wasmer-0.17.1/ sh -s 0.17.1 | |
# Install Wasmer 1.0 | |
curl https://get.wasmer.io -sSfL | WASMER_DIR=`pwd`/wasmer-1.0/ sh | |
# Timings for Wasmer 0.17.1 | |
time ./wasmer-0.17.1/bin/wasmer --disable-cache --backend=singlepass clang.wasm -- -V |
use wasmer::{Store, Module, Instance, Value, imports}; | |
fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let module_wat = r#" | |
(module | |
(type $t0 (func (param i32) (result i32))) | |
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32) | |
get_local $p0 | |
i32.const 1 | |
i32.add)) |
#include <stdio.h> | |
int main(int argc, char **argv) | |
{ | |
if (argc < 2) { | |
printf("Hello, WASI!\n"); | |
} else { | |
printf("Hello, %s!\n", argv[1]); | |
} | |
} |
[package] | |
name = "example-cli" | |
version = "0.0.1" | |
description = "An example WASI cli app" | |
repository = "https://github.com/wapm-packages/example-cli" | |
homepage = "https://github.com/wapm-packages/example-cli" | |
[[module]] | |
name = "example-cli" | |
source = "example-cli.wasm" |
(interface "wasi_unstable" | |
;; Here's a bunch of function imports! | |
(func (import "wasi_unstable" "args_get") (param i32 i32) (result i32)) | |
(func (import "wasi_unstable" "args_sizes_get") (param i32 i32) (result i32)) | |
(func (import "wasi_unstable" "clock_res_get") (param i32 i32) (result i32)) | |
(func (import "wasi_unstable" "clock_time_get") (param i32 i32 i32) (result i32)) | |
(func (import "wasi_unstable" "environ_get") (param i32 i32) (result i32)) | |
(func (import "wasi_unstable" "environ_sizes_get") (param i32 i32) (result i32)) | |
(func (import "wasi_unstable" "fd_advise") (param i32 i64 i64 i32) (result i32)) | |
(func (import "wasi_unstable" "fd_allocate") (param i32 i64 i64) (result i32)) |
// This is an example on how a cache system could work. | |
// It enforces a very useful pattern for caching: | |
// - serializing (cache.save) | |
// - deserializing (cache.load) | |
// This abstracts the responsibility on how to load or how to save | |
// outside, so it can be a FileSystem, a HashMap in memory, ... | |
// We get the hash from the binary | |
let hash: WasmHash = get_wasm_hash(&wasm_binary); |
extern crate wasmer_clif_backend; | |
extern crate wasmer_runtime; | |
use std::{ | |
fs::File, | |
io::prelude::*, | |
str, | |
}; | |
use wasmer_clif_backend::CraneliftCompiler; |
This is a comparison of the different async/await strategies.
Python is the only language that doesn't execute the coroutines/tasks until you await for them.
import graphene | |
from graphene import relay | |
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField | |
class Employee(SQLAlchemyObjectType): | |
class Meta: | |
model = EmployeeModel | |
interfaces = (relay.Node, ) |