GithubHelp home page GithubHelp logo

bandorko / xk6-interpret Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dgzlopes/xk6-interpret

0.0 0.0 0.0 222 KB

A k6 extension for interpreting Go code.

License: GNU Affero General Public License v3.0

JavaScript 52.69% Go 47.31%

xk6-interpret's Introduction

xk6-interpret

This is a k6 extension using the xk6 system.

❗ This is a TOY extension. USE AT YOUR OWN RISK! OR... DON'T USE IT!

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Clone xk6:
git clone https://github.com/k6io/xk6.git
cd xk6
  1. Build the binary:
CGO_ENABLED=1 go run ./cmd/xk6/main.go build master \
  --with github.com/dgzlopes/xk6-interpret

Example

import interpret from 'k6/x/interpret';

export default function() {
    var result = interpret.run(
    `package interpret
    
    import "fmt"


    // fibonacci is a function that returns
    // a function that returns an int.
    func fibonacci() func() int {
        x, y := 0, 1
        return func() int {
            x, y = y, x + y
            fmt.Println("Calculated:",x)
            return x
        }
    }

    func Run(s interface{}) interface{} {
        f := fibonacci()
        var results []int
        var i int64
        for i = 0; i < s.(int64); i++ {
            results = append(results,f())
        }
        return results
    }
    `,
    10
    );

    console.log(`Results: ${result}`)
}

Result output:

$ ./k6 run script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: ../example.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

Calculated: 1
Calculated: 2
Calculated: 4
Calculated: 8
Calculated: 16
Calculated: 32
Calculated: 64
Calculated: 128
Calculated: 256
Calculated: 512
INFO[0000] Results: 1,2,4,8,16,32,64,128,256,512         source=console

running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

    data_received........: 0 B 0 B/s
    data_sent............: 0 B 0 B/s
    iteration_duration...: avg=1.16ms min=1.16ms med=1.16ms max=1.16ms p(90)=1.16ms p(95)=1.16ms
    iterations...........: 1   66.559293/s

xk6-interpret's People

Contributors

dgzlopes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.