-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.go
58 lines (46 loc) · 1.59 KB
/
benchmark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// File: benchmark.go
// Berikut adalah program untuk benchmarking pembuatan dan verifikasi token JWT dengan algoritma RSA dan HMAC SHA-3.
package main
import (
"crypto/rsa"
"fmt"
"time"
)
// Function to benchmark RSA token creation and verification
func benchmarkRSA(privateKey *rsa.PrivateKey, publicKey *rsa.PublicKey) {
// Benchmark token creation
start := time.Now()
for i := 0; i < 1000; i++ {
createRSAToken(privateKey)
}
creationTime := time.Since(start)
// Benchmark token verification
tokenString, _ := createRSAToken(privateKey)
fmt.Println("JWT hasil generasi menggunakan RSA: ", tokenString+"\n")
start = time.Now()
for i := 0; i < 1000; i++ {
verifyRSAToken(tokenString, publicKey)
}
verificationTime := time.Since(start)
fmt.Println("1000x JWT Creation using RSA Time:", creationTime)
fmt.Println("1000x JWT Verification using RSA Time:", verificationTime)
}
// Function to benchmark HMAC SHA-3 token creation and verification
func benchmarkHMACSHA3(hmacSecret []byte) {
// Benchmark token creation
start := time.Now()
for i := 0; i < 1000; i++ {
createHMACSHA3Token(hmacSecret)
}
creationTime := time.Since(start)
// Benchmark token verification
tokenString, _ := createHMACSHA3Token(hmacSecret)
fmt.Println("\nJWT hasil generasi menggunakan HMAC SHA-3: ", tokenString+"\n")
start = time.Now()
for i := 0; i < 1000; i++ {
verifyHMACSHA3Token(tokenString, hmacSecret)
}
verificationTime := time.Since(start)
fmt.Println("1000x JWT Creation using HMAC SHA-3 Time:", creationTime)
fmt.Println("1000x JWT Verification using HMAC SHA-3 Time:", verificationTime)
}