Skip to content

Instantly share code, notes, and snippets.

View agusrichard's full-sized avatar

Agus Richard Lubis agusrichard

View GitHub Profile
import http from 'k6/http'
import { sleep, check } from 'k6'
import { Rate, Trend } from 'k6/metrics'
// Custom defined metrics
const lowerThan2sRate = new Rate('lower_than_2s')
const durationInSeconds = new Trend('duration_in_seconds')
// This BASE_URL won't work if you're using Docker.
// You'll need to know the IP address of the host.
export function teardown(data) {
const params = {
headers: {
Authorization: `Bearer ${data.token}`
}
}
// To clear/truncate the injected table we need token
http.get(`${BASE_URL}/users/clear`, params)
}
export function setup() {
const authParams = {
headers: { 'Content-Type': 'application/json' },
}
const authPayload = {
email: '[email protected]',
password: 'user1',
fullname: 'user1'
}
// 1. init code
export function setup() {
// 2. setup code
}
export default function (data) {
// 3. VU code
}
import http from 'k6/http'
import { sleep } from 'k6'
// This BASE_URL won't work if you're using Docker.
// You'll need to know the IP address of the host.
// Then replace localhost with the IP address.
const BASE_URL = 'http://localhost:3000'
export default function() {
const res = http.get(BASE_URL)
@agusrichard
agusrichard / main.go
Last active September 18, 2021 17:33
package main
import (
"fmt"
"math/rand"
"net/http"
"strconv"
"time"
)
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"strconv"
"testing"
)
@agusrichard
agusrichard / main.go
Last active September 18, 2021 17:24
package main
import (
"fmt"
"math/rand"
"net/http"
"strconv"
"time"
)
package main
import (
"fmt"
"math/rand"
"net/http"
"strconv"
"time"
)
@agusrichard
agusrichard / main_test.go
Created September 18, 2021 14:48
main_test.go
package main
import "testing"
func BenchmarkCalculate(b *testing.B) {
for n := 0; n < b.N; n++ {
Calculate(1, 2)
}
}