benchmark of cairo

This commit is contained in:
Ryan Oldenburg 2020-12-13 02:35:02 -06:00
parent 6e55ecc7d4
commit 2b76cfbfc7
3 changed files with 35 additions and 85 deletions

View file

@ -0,0 +1,35 @@
import cairo, math, benchy, pixie, chroma
var
surface = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000)
ctx = surface.create()
ctx.setSourceRgba(0, 0, 0, 1)
ctx.fill()
ctx.setSourceRgba(0, 0, 1, 1)
timeIt "cairo":
ctx.newPath()
ctx.moveTo(0, 0)
ctx.lineTo(500, 0)
ctx.lineTo(500, 500)
ctx.lineTo(0, 500)
ctx.closePath()
ctx.fill()
surface.flush()
discard surface.writeToPng("cairo.png")
var a = newImage(1000, 1000)
a.fill(rgba(0, 0, 0, 255))
timeIt "pixie":
let p = newPath()
p.moveTo(0, 0)
p.lineTo(500, 0)
p.lineTo(500, 500)
p.lineTo(0, 500)
p.closePath()
a.fillPath(p, rgba(0, 0, 255, 255))
discard surface.writeToPng("pixie.png")

View file

@ -1,28 +0,0 @@
import cairo, math, times
var
surface = imageSurfaceCreate(FORMAT_ARGB32, 256, 256)
ctx = surface.create()
let start = epochTime()
ctx.setSourceRGB(0, 0, 1)
ctx.newPath() # current path is not consumed by ctx.clip()
ctx.rectangle(96, 96, 128, 128)
ctx.fill()
ctx.setSourceRGB(0, 1, 0)
ctx.newPath() # current path is not consumed by ctx.clip()
ctx.rectangle(64, 64, 128, 128)
ctx.fill()
for i in 0 .. 10000:
ctx.setSourceRGB(1, 0, 0)
ctx.newPath() # current path is not consumed by ctx.clip()
ctx.rectangle(32, 32, 128, 128)
ctx.fill()
echo epochTime() - start
discard surface.writeToPng("cairotest.png")

View file

@ -1,57 +0,0 @@
import staticglfw, opengl, pixie, times
if init() == 0:
raise newException(Exception, "Failed to Initialize GLFW")
windowHint(VISIBLE, false.cint)
var window = createWindow(512, 512, "GLFW3 WINDOW", nil, nil)
window.makeContextCurrent()
# This must be called to make any GL function work
loadExtensions()
let start = epochTime()
# Draw red color screen.
glClearColor(1, 1, 1, 1)
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glTranslatef(-0.25, -0.25, 0)
glBegin(GL_QUADS)
glColor3f(1.0, 0.0, 0.0)
glVertex2f(0.0, 0.0)
glVertex2f(1.0, 0.0)
glVertex2f(1.0, 1.0)
glVertex2f(0.0, 1.0)
glEnd()
glTranslatef(-0.25, -0.25, 0)
glBegin(GL_QUADS)
glColor3f(0.0, 0.0, 1.0)
glVertex2f(0.0, 0.0)
glVertex2f(1.0, 0.0)
glVertex2f(1.0, 1.0)
glVertex2f(0.0, 1.0)
glEnd()
glTranslatef(-0.25, -0.25, 0)
glBegin(GL_QUADS)
glColor3f(0.0, 1.0, 0.0)
glVertex2f(0.0, 0.0)
glVertex2f(1.0, 0.0)
glVertex2f(1.0, 1.0)
glVertex2f(0.0, 1.0)
glEnd()
var screen = newImage(512, 512)
glReadPixels(
0, 0,
512, 512,
GL_RGBA, GL_UNSIGNED_BYTE,
screen.data[0].addr
)
echo epochTime() - start
screen.writeFile("screen.png")