Site icon akquinet AG – Blog

Measuring of Swift by looking at a simple web service

I ran across a colleague’s article recently and figured that the Swift programming language would be a nice addition to his comparison. In order to remedy this I implemented the admittedly very simple web service in Swift and measured both its performance and size. Then I followed the given structure of the article in terms of how to present my relevant results. You may find these subsequently.

 Implementation effort

A simple web service shall be implemented that adds two numbers and returns the result in some way. The service shall be available via HTTP at a certain address. In order to make this happen with Swift I used the Kitura HTTP server which is available here. The code that implements the web service looks like this:

import Kitura

let router = Router()
router.get("/add/:summand1/and/:summand2") { request, response, next in
    if let summand1 = Int(request.parameters["summand1"] ?? "0") {
        if let summand2 = Int(request.parameters["summand2"] ?? "0") {
            response.status(.OK).send("The sum of \(summand1) and \(summand2) equals \(summand1 + summand2).\n")
    response.status(.badRequest).send("ERROR: Cannot calculate with non integer values.\n")

Kitura.addHTTPServer(onPort: 8080, with: router)

The code is also available on Github.


If you read my colleague’s blog post, you may be familiar with the following graphs that I supplemented with my own results.

Lines of code

As you can see below, the Swift package comes very cheap in terms of LOC. The overall count of all self-implemented code lines is 27. That also includes the manifest file (Package.swift) which is not displayed above but can be verified on Github.


To me there are two interesting values in terms of used disc space:

  1. Size of the resulting artifact
  2. Size of the Docker image the artifact is running in

Concerning 1. the Swift web service finishes second with a total size of 3.426 megabytes right behind the Java implementation for Wildfly.

When it comes to the total size of the Docker image (2.) Swift is sorely afflicted with the fact that right now Swift apps (outside iOS) are only supported on MacOS and Ubuntu Linux. There is a Docker image for Kitura (Ubuntu) but unfortunately this is a real heavyweight with a total size of 1.24 gigabytes.

As a result Swift suffers a crushing defeat in this category. However, this may change in the future, e.g. if Swift could run in an Alpine based Docker container.


In order to assure comparability any time measurements should be done on the same environment. I cannot ensure this right now, so I decided to deliver the time measurement results in a subsequent blog post.




Exit mobile version