<commit_before>//
//  AppDelegate.swift
//  CollectionBenchmark
//
//  Created by <NAME> on 2015-12-21.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!

    func benchmarkDidFinish(name: String, result: BenchmarkResult) {
        var file = ""
        file += "Parameter\tExperiment\tSize\tData\n"
        for (key, data) in result.data {
            for d in data.durations {
                file += key.param
                file += "\t"
                file += key.experiment
                file += "\t"
                file += String(key.size)
                file += "\t"
                file += String(d.timeInterval * 1000)
//                file += String(data.average.timeInterval * 1000)
//                file += "\t"
//                file += String(data.relativeStandardDeviation) + "%"
                file += "\n"
            }
        }
        let fm = NSFileManager.defaultManager()
        let ws = NSWorkspace.sharedWorkspace()
        do {
            let desktop = try fm.URLForDirectory(.DesktopDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
            let outputfile = desktop.URLByAppendingPathComponent("benchmark.tsv", isDirectory: false)
            try (file as NSString).writeToURL(outputfile, atomically: true, encoding: NSUTF8StringEncoding)
            ws.openURL(outputfile)
            
        }
        catch let error {
            NSAlert(error: error as NSError).beginSheetModalForWindow(self.window) { response in
                print("Well OK then")
            }
        }
    }

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {

            var last: Int? = nil
            let sizes = (0...18*4).map { Int(floor(pow(2, Double($0) / 4))) }.filter { i in
                guard last != i else { return false }
                last = i
                return true
            }
            let b1 = insertionBenchmark("small", sizes: sizes) { i in i }
            let object = NSObject()
            let b2 = insertionBenchmark("bigger", sizes: sizes) { i in (i, Double(i), "\(i)", [i, 2 * i, 3 * i], object) }

            let results = b2.run(10)
            dispatch_async(dispatch_get_main_queue()) {
                self.benchmarkDidFinish("Insertion", result: results)
            }
        }

    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }


}
<commit_msg>Dump results to a unique file.<commit_after>//
//  AppDelegate.swift
//  CollectionBenchmark
//
//  Created by <NAME> on 2015-12-21.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!

    func benchmarkDidFinish(name: String, result: BenchmarkResult) {
        var file = ""
        file += "Parameter\tExperiment\tSize\tData\n"
        for (key, data) in result.data {
            for d in data.durations {
                file += key.param
                file += "\t"
                file += key.experiment
                file += "\t"
                file += String(key.size)
                file += "\t"
                file += String(d.timeInterval * 1000)
//                file += String(data.average.timeInterval * 1000)
//                file += "\t"
//                file += String(data.relativeStandardDeviation) + "%"
                file += "\n"
            }
        }
        let fm = NSFileManager.defaultManager()
        let ws = NSWorkspace.sharedWorkspace()
        do {
            let formatter = NSDateFormatter()
            formatter.dateFormat = "yyyy-MM-dd HH.mm.ss" // Can't use ISO8601 because filesystems :-(
            let startDate = formatter.stringFromDate(result.start)

            let desktop = try fm.URLForDirectory(.DesktopDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
            let filename = "benchmark - \(startDate) - \(result.name).tsv"
            let outputfile = desktop.URLByAppendingPathComponent(filename, isDirectory: false)
            try (file as NSString).writeToURL(outputfile, atomically: true, encoding: NSUTF8StringEncoding)
            ws.openURL(outputfile)
            
        }
        catch let error {
            NSAlert(error: error as NSError).beginSheetModalForWindow(self.window) { response in
                print("Well OK then")
            }
        }
    }

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {

            var last: Int? = nil
            let sizes = (0...18*4).map { Int(floor(pow(2, Double($0) / 4))) }.filter { i in
                guard last != i else { return false }
                last = i
                return true
            }
            let b1 = insertionBenchmark("small", sizes: sizes) { i in i }
            let object = NSObject()
            let b2 = insertionBenchmark("bigger", sizes: [50000]) { i in (i, Double(i), "\(i)", [i, 2 * i, 3 * i], object) }
            let b3 = lookupBenchmark("bigger", count: 100000, sizes: [10000], factory: { i in (i, Double(i), "\(i)", [i, 2 * i, 3 * i], object) })

            let results = b2.run(10)
            dispatch_async(dispatch_get_main_queue()) {
                self.benchmarkDidFinish("Insertion", result: results)
            }
        }

    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }


}

{'fraction_non_alphanumeric': 0.11316516931582585, 'fraction_numerical': 0.016413268832066345, 'mean_word_length': 1.8672610203070827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1777787', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1588, 'n_words': 413}