Skip to content

Commit 4e84861

Browse files
committed
more tests
1 parent 1733b6d commit 4e84861

13 files changed

Lines changed: 147 additions & 2622 deletions

PerfomanceTests/readme.md

Lines changed: 147 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ Number of successful requests in 50 seconds **(higher is better)**.
3535

3636
### Other Platforms
3737

38-
| Records | Function | AOT [1](#1-aot) | JIT [2](#2-jit) | EF [3](#3-ef) | ADO [4](#4-ado) | Djang [5](#5-django) |
39-
| ------: | ---------: | ---------: | --------: | --------: | --------: | --------: |
40-
| 10 | `perf_test` | 423,515 | 606,410 | 337,612 | 440,896 | 21,193 |
41-
| 100 | `perf_test` | 100,542 | 126,154 | 235,331 | 314,198 | 18,345 |
42-
| 10 | `perf_test_arrays` | 292,489 | 419,707 | 254,787 | 309,059 | 19,011 |
43-
| 100 | `perf_test_arrays` | 68,316 | 80,906 | 113,663 | 130,471 | 11,452 |
38+
| Records | Function | AOT [1](#1-aot) | JIT [2](#2-jit) | EF [3](#3-ef) | ADO [4](#4-ado) | Django [5](#5-django) | Express [6](#6-express) | GO [6](#6-go) |
39+
| ------: | ---------: | ---------: | --------: | --------: | --------: | --------: | --------: | --------: |
40+
| 10 | `perf_test` | 423,515 | 606,410 | 337,612 | 440,896 | 21,193 | 160,241 | 78,530 |
41+
| 100 | `perf_test` | 100,542 | 126,154 | 235,331 | 314,198 | 18,345 | 58,130 | 55,119 |
42+
| 10 | `perf_test_arrays` | 292,489 | 419,707 | 254,787 | 309,059 | 19,011 | 91,987 | N/A |
43+
| 100 | `perf_test_arrays` | 68,316 | 80,906 | 113,663 | 130,471 | 11,452 | 17,896 | N/A |
4444

4545
#### 1) AOT
4646

@@ -206,6 +206,147 @@ class PerfTestArrays(APIView):
206206
return Response([dict(zip(columns, row)) for row in data])
207207
```
208208

209+
#### 6) Express
210+
211+
NodeJS v20.11.1, express v4.18.3, pg 8.11.3
212+
213+
```js
214+
app.post('/api/perf_test', async (req, res) => {
215+
try {
216+
const { _records, _text_param, _int_param, _ts_param, _bool_param } = req.body;
217+
const queryResult = await pool.query(
218+
'select id1, foo1, bar1, datetime1, id2, foo2, bar2, datetime2, long_foo_bar, is_foobar from perf_test($1, $2, $3, $4, $5)',
219+
[_records, _text_param, _int_param, _ts_param, _bool_param]);
220+
res.json(queryResult.rows);
221+
} catch (error) {
222+
res.status(500).json({ error: error.message });
223+
}
224+
});
225+
226+
app.post('/api/perf_test_arrays', async (req, res) => {
227+
try {
228+
const { _records, _text_param, _int_param, _ts_param, _bool_param } = req.body;
229+
const queryResult = await pool.query(
230+
'select id1, foo1, bar1, datetime1, id2, foo2, bar2, datetime2, long_foo_bar, is_foobar from perf_test_arrays($1, $2, $3, $4, $5)',
231+
[_records, _text_param, _int_param, _ts_param, _bool_param]);
232+
res.json(queryResult.rows);
233+
} catch (error) {
234+
res.status(500).json({ error: error.message });
235+
}
236+
});
237+
```
238+
239+
#### 7) GO
240+
241+
go version go1.13.8
242+
243+
```go
244+
package main
245+
246+
import (
247+
"database/sql"
248+
"encoding/json"
249+
"log"
250+
"net/http"
251+
252+
"github.com/gorilla/mux"
253+
_ "github.com/lib/pq"
254+
)
255+
256+
const (
257+
host = "127.0.0.1"
258+
port = "5432"
259+
user = "postgres"
260+
password = "postgres"
261+
dbname = "perf_tests"
262+
)
263+
264+
type PerfTestResult struct {
265+
ID1 int `json:"id1"`
266+
Foo1 string `json:"foo1"`
267+
Bar1 string `json:"bar1"`
268+
Datetime1 string `json:"datetime1"`
269+
ID2 int `json:"id2"`
270+
Foo2 string `json:"foo2"`
271+
Bar2 string `json:"bar2"`
272+
Datetime2 string `json:"datetime2"`
273+
LongFooBar string `json:"long_foo_bar"`
274+
IsFooBar bool `json:"is_foobar"`
275+
}
276+
277+
func main() {
278+
// Initialize a new router
279+
router := mux.NewRouter()
280+
281+
// Define your endpoint
282+
router.HandleFunc("/api/perf_test", PerfTestFunction).Methods("POST")
283+
284+
// Start the server
285+
log.Fatal(http.ListenAndServe(":8080", router))
286+
}
287+
288+
func PerfTestFunction(w http.ResponseWriter, r *http.Request) {
289+
// Parse JSON parameters from request body
290+
var params map[string]interface{}
291+
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
292+
http.Error(w, err.Error(), http.StatusBadRequest)
293+
return
294+
}
295+
296+
// Connect to PostgreSQL database
297+
connStr := "host=" + host + " port=" + port + " user=" + user + " password=" + password + " dbname=" + dbname + " sslmode=disable"
298+
db, err := sql.Open("postgres", connStr)
299+
if err != nil {
300+
http.Error(w, err.Error(), http.StatusInternalServerError)
301+
return
302+
}
303+
defer db.Close()
304+
305+
// Call PostgreSQL function
306+
rows, err := db.Query("SELECT id1, foo1, bar1, datetime1, id2, foo2, bar2, datetime2, long_foo_bar, is_foobar from perf_test($1, $2, $3, $4, $5)",
307+
params["_records"], params["_text_param"], params["_int_param"], params["_ts_param"], params["_bool_param"])
308+
if err != nil {
309+
http.Error(w, err.Error(), http.StatusInternalServerError)
310+
return
311+
}
312+
defer rows.Close()
313+
314+
// Prepare the result slice
315+
var results []PerfTestResult
316+
317+
// Iterate over the rows returned by the query
318+
for rows.Next() {
319+
var result PerfTestResult
320+
if err := rows.Scan(
321+
&result.ID1, &result.Foo1, &result.Bar1, &result.Datetime1,
322+
&result.ID2, &result.Foo2, &result.Bar2, &result.Datetime2,
323+
&result.LongFooBar, &result.IsFooBar,
324+
); err != nil {
325+
http.Error(w, err.Error(), http.StatusInternalServerError)
326+
return
327+
}
328+
results = append(results, result)
329+
}
330+
331+
// Check for errors during row iteration
332+
if err := rows.Err(); err != nil {
333+
http.Error(w, err.Error(), http.StatusInternalServerError)
334+
return
335+
}
336+
337+
// Convert the result slice to JSON
338+
jsonResponse, err := json.Marshal(results)
339+
if err != nil {
340+
http.Error(w, err.Error(), http.StatusInternalServerError)
341+
return
342+
}
343+
344+
// Set Content-Type header and write response
345+
w.Header().Set("Content-Type", "application/json")
346+
w.Write(jsonResponse)
347+
}
348+
```
349+
209350
## Tests Functions
210351

211352
```sql

PerfomanceTests/results/django-perf_test-100rec.txt

Lines changed: 0 additions & 218 deletions
This file was deleted.

0 commit comments

Comments
 (0)