Skip to content

main.aug ​

JSON benchmark · Source and specification

Files in this project

Code ​

aug
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
import parse from json
import Payload from data
int checksum = 0
int index = 0
try:
    while index < 5000:
        document = parse(input="{\"id\":7,\"message\":\"hello\",\"values\":[1,2,3]}")
        payload = document.decode<Payload>()
        encoded = Json(value=payload).stringify()
        checksum = checksum + payload.id + encoded.length()
        index = index + 1
    print(value=checksum)
catch JsonError error:
    exit(status=1)
aug
// aug-spec: "main.aug.md" explains this file. Read it before changes; refresh with aug spec.
import parse from json
import Payload from data
int checksum = 0
int index = 0
try {
    while index < 5000 {
        document = parse(input="{\"id\":7,\"message\":\"hello\",\"values\":[1,2,3]}")
        payload = document.decode<Payload>()
        encoded = Json(value=payload).stringify()
        checksum = checksum + payload.id + encoded.length()
        index = index + 1
    }
    print(value=checksum)
}
catch JsonError error {
    exit(status=1)
}

Compiled specification ​

Interactions and sequences

Startup ​

It sets checksum and index separately, each to 0. While index is less than 5000, it sets document to parse with input "{\"id\":7,\"message\":\"hello\",\"values\":[1,2,3]}". It sets payload to document.decode for Payload. It sets encoded to stringify on a Json with value from payload. source

It sets checksum to (checksum plus payload.id) plus the byte length of encoded. It increases index by 1. After the loop, it prints checksum. If this work raises JsonError, it calls exit with status 1. source

Dependencies ​

It uses parse from json. It uses Payload (id) from data.

Built-in operations follow the language reference.

Last updated:

The world runs on language