Skip to content

Commit 59c1d9f

Browse files
committed
Added proving time and instructions
1 parent fd36b99 commit 59c1d9f

File tree

14 files changed

+1347
-2044
lines changed

14 files changed

+1347
-2044
lines changed

test_suite/README.md

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
# Test suite for zk-regex + Noir
22

3+
This test-suite is a tool for testing and benchmarking the zk-regex library module that generates Noir code to check if certain regex is matched.
4+
35
## Requirements
46

57
- Install zk-regex command following the instructions in the documentation.
68
- Install Noir.
9+
- Install the `hyperfine` tool.
710

811
## How to run
912

10-
### Database
13+
To execute the testing and/or the benchmarking, you need to fill a JSON database that will be used for the testing and/or benchmarking. The testing and the benchmarking are two separate processes. This means that you may execute the testing without the benchmarking, or the benchmarking without the testing, or execute both the testing and the benchmarking. However, both processes will use the same database for their ends. It is important to add that if you want to execute just the testing or just the benchmarking, some of the fields are not mandatory as we will explain next. The basic structure for the database is as follows:
14+
15+
```json
16+
{
17+
"database": [
18+
<sample>,
19+
<sample>,
20+
<sample>,
21+
]
22+
}
23+
24+
```
25+
26+
where `<sample>` is a JSON object with certain required fields. The instructions to fill the database are presented below.
27+
28+
## Instructions for testing
29+
30+
Each sample for testing can be one of two types: raw, or decomposed. "Raw" means that the regex is specified as just one string, while "decomposed" means that the regex is specified in fragments according to the zk-regex specification. Below you will find an example of how to specify a database with both types of specification. It is important to notice that the database can have samples with a mixture of both types: some samples may be "raw", and other samples may be "decomposed".
1131

1232
```json
1333
{
@@ -51,14 +71,63 @@
5171
]
5272
}
5373
```
54-
### Execute tests
5574

75+
To execute the tests, you simply run.
76+
77+
```bash
78+
RUST_LOG=info cargo run -- -t
79+
```
80+
81+
## Instructions for benchmarking
82+
83+
This tool allows you to benchmark the source code to evaluate the performance. The benchmarking requires to add additional flags and information to the database presented in the previous section. It is important to make clear that if you just want to execute the test, the modifications to the database associated with the benchmark **are not mandatory**.
84+
85+
The benchmarking tool supports the following features:
86+
87+
- If you want to benchmark all the samples, you can add the `"bench_all": true` to the database as follows:
88+
89+
```json
90+
{
91+
"bench_all": true,
92+
"database": [
93+
<sample>,
94+
<sample>,
95+
<sample>,
96+
]
97+
}
98+
```
99+
100+
This flag is optional.
101+
- You may want to execute benchmarks not for all the samples but for some of them. If you want to execute the benchmark for some of the samples but not for all, you can add the flag `"with_bench": true` to benchmark that sample. This flag is considered optional, and if you do not add it, the default value will be considered as `false`.
102+
- There are two types of benchmarking:
103+
- *without time*: this mode of benchmarking means that the report will include just the gate-count of the circuit generated by the zk-regex library, but this mode does not measure the proving time. To execute the benchmarking in this mode you must execute the following command:
104+
105+
```bash
106+
RUST_LOG=info cargo run -- [OPTIONS] no-time
107+
```
108+
109+
- *with time*: this mode of benchmarking measures the gate-count as in the previous mode, and also measures the proving time of 5 executions of the Noir project. To execute this you need to add the field `"benchmark_str"` with a string that must successfully match the regex. This string will be used as the witness for the prove. If you **do not** want to benchmark the proving time, you can omit this field in the database. To run the benchmarking *with time*, you must execute the following command:
110+
111+
```bash
112+
RUST_LOG=info cargo run -- [OPTIONS] with-time
113+
```
114+
115+
If you want to execute the benchmarking **without** the testing, you can omit the `-t` flag in the execution command as shown below:
116+
117+
```bash
118+
RUST_LOG=info cargo run -- <no-time | with-time>
56119
```
57-
$ RUST_LOG=info cargo run
120+
121+
## Execution of testing and benchmarking simultaneously
122+
123+
If you want to execute both the testing and the benchmarking you need to follow the instructions presented above for the benchmarking and the testing independently. Then you can execute the following command:
124+
125+
```bash
126+
RUST_LOG=info cargo run -- -t <no-time | with-time>
58127
```
59128

60129
## Limitations
61130

62-
For some regexes the random sampling is not possible, because the sampling library is limited. For example the end anchor (`$`) is not supported.
131+
For some regexes the random sampling is not possible, because the sampling library is limited. For example the end anchor (`$`) is not supported.
63132

64-
Random sample testing for the `gen_substrs` setting is only support for `decomposed`. In the `raw` setting, the substrings are determined via a json file that contains the transition information. Determining what the substring parts are, would be quite involved since it requires building the DFA.
133+
Random sample testing for the `gen_substrs` setting is only support for `decomposed`. In the `raw` setting, the substrings are determined via a json file that contains the transition information. Determining what the substring parts are, would be quite involved since it requires building the DFA.

test_suite/bench_result.csv

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
acir_opcodes,circuit_size,regex,with_gen_substr
2-
114,17865,email was meant for @[a-z]+,true
3-
59,7808,1=(a|b) (2=(b|c)+ )+d,true
1+
acir_opcodes,circuit_size,regex,with_gen_substr,proving_time
2+
43,3175,(a|b)+c,false,0.18447697588

test_suite/decomposed.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"parts":[{"is_public":false,"regex_def":"ab"},{"is_public":true,"regex_def":"cd"}]}
1+
{"parts":[{"is_public":false,"regex_def":"(\\r\\n|^)subject:"},{"is_public":true,"regex_def":"[^\\r\\n]+"},{"is_public":false,"regex_def":"\\r\\n"}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"input" = [109, 98, 45, 99, 99, 100, 99, 100, 100, 100, 100, 99, 100, 100, 99, 99]
1+
input = [97, 98, 97, 97, 98, 98, 97, 98, 97, 99]

test_suite/execution_project/proving_time_resuls.json

Whitespace-only changes.

0 commit comments

Comments
 (0)