Skip to content

Instantly share code, notes, and snippets.

View syrusakbary's full-sized avatar
💪
Building @wasmerio

Syrus Akbary syrusakbary

💪
Building @wasmerio
View GitHub Profile
@syrusakbary
syrusakbary / benchmark.md
Created March 16, 2024 20:16
Pystone benchmark comparison (Native vs CPython interpreter vs Nuitka)

Native

When executing Python natively:

$ python pystone.py
Pystone(1.1) time for 50000 passes = 0.129016
This machine benchmarks at 387549 pystones/second
@syrusakbary
syrusakbary / wasmer-compile-bench.sh
Created December 10, 2020 21:18
Wasmer Compilation Benchmark - 0.x vs 1.0
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))
@syrusakbary
syrusakbary / wasmer_cache.rs
Last active February 14, 2019 20:13
Wasmer cache example
// 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);
@syrusakbary
syrusakbary / main.rs
Created January 21, 2019 21:27 — forked from lachlansneff/main.rs
Wasmer Rust Embedder App Example
extern crate wasmer_clif_backend;
extern crate wasmer_runtime;
use std::{
fs::File,
io::prelude::*,
str,
};
use wasmer_clif_backend::CraneliftCompiler;
@syrusakbary
syrusakbary / README.md
Last active June 15, 2017 23:35
Async/Await examples

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, )