The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
// Graphql-Cr
BenchmarkGraphQLGolang-8 200000 5986 ns/op
PASS
ok _/home/alex/Projects/Crystal/graphql 1.273s
=====================================================
// Graphql-Go
graphql-cr 28.37k ( 35.25µs) (±52.60%) fastest
{
"hello": "world"
}
Crystal -> 35.25µs fastest
Go -> 1273000µs (x36113.47 slower)
require "graphql-crystal"
require "benchmark"
schema_definition = <<-graphql_schema
schema {
query: QueryType
}
type QueryType {
hello: String
}
graphql_schema
schema = GraphQL::Schema.from_schema(schema_definition)
schema.resolve do
query "hello" { "world" }
end
Benchmark.ips do |x|
x.report("graphql-cr") { schema.execute("{hello}") }
end
print "\n" + schema.execute("{ hello }")["data"].to_pretty_json
import (
"testing"
"github.com/playlyfe/go-graphql"
)
var schema = `
type QueryType {
hello: String
}
`
var resolvers = map[string]interface{}{
"QueryType/hello": func(params *graphql.ResolveParams) (interface{}, error) {
return "world", nil
},
}
var executor, _ = graphql.NewExecutor(schema, "QueryType", "", resolvers)
func BenchmarkGraphQLGolang(b *testing.B) {
for i := 0; i < b.N; i++ {
context := map[string]interface{}{}
variables := map[string]interface{}{}
executor.Execute(context, "{hello}", variables, "")
}
}
interface{}
is an anonymous interface type (in Go, that's "any type goes"), and the following {} could be anything, possibly an empty body for the anon interface we just defined (?)