Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crystal-vs-go

Comparative example: the same API implemented in Crystal (Kemal) and Go (Gin).

Requirements

  • Crystal >= 1.17
  • Go >= 1.22
  • SQLite3 CLI (for seeding)
  • wrk (for load testing)

Database (SQLite)

  1. Seed data from the repository root:
sqlite3 posts.db < db/seed.sql
  1. Location: posts.db is created at the repository root. The Crystal service runs from the repo root, the Go service runs from go/. Go uses ../posts.db by default to point to the root database file.

Database (PostgreSQL)

  1. Create database (one of):
createdb posts
# or
psql -h localhost -U postgres -c "CREATE DATABASE crystal-vs-go;"
  1. Seed from the repository root:
export DATABASE_URL="postgres://postgres:postgres@localhost:5432/crystal-vs-go?sslmode=disable"
psql "$DATABASE_URL" -f db/seed.sql

Notes:

  • The seed script is portable and works for both SQLite and PostgreSQL.
  • Both apps read the database from DATABASE_URL. Use postgres://... for Postgres or sqlite3:/absolute/path/to/posts.db for SQLite.

Crystal (Kemal)

Sources live under crystal/.

Run:

cd crystal
shards install
crystal run src/main.cr
# Test
curl http://localhost:3000/
curl http://localhost:3000/posts

Configuration:

  • Default DB URL: sqlite3:./posts.db (set DATABASE_URL to postgres://... for Postgres)
  • Override: DATABASE_URL=sqlite3:/absolute/path/posts.db crystal run src/main.cr

Go (Gin)

Sources live under go/.

Run:

cd go
go mod tidy
go run .
# Test
curl http://localhost:8080/
curl http://localhost:8080/posts

Configuration:

  • Default DSN: ../posts.db (relative to go/ directory)
  • SQLite: DATABASE_URL=sqlite3:../posts.db go run .
  • Postgres: DATABASE_URL=postgres://postgres:postgres@localhost:5432/posts?sslmode=disable go run .

Layout

  • crystal/: Crystal app (Kemal)
  • go/: Go app (Gin)
  • db/seed.sql: seed script for users and posts (5 posts per user)
  • posts.db: SQLite database file at repo root

Load testing (wrk)

Crystal (port 3000):

wrk -c 100 -d 30 http://localhost:3000/posts

Go (port 8080):

wrk -c 100 -d 30 http://localhost:8080/posts

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages