forked from blanu/Swift-BigInt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.swift
106 lines (93 loc) · 2.57 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import Foundation
// Run Benchmarks
Benchmarks.BDoubleConverging()
Benchmarks.exponentiation()
Benchmarks.factorial()
Benchmarks.fibonacci()
Benchmarks.Matrix1()
Benchmarks.mersennes()
Benchmarks.BIntToString()
Benchmarks.StringToBInt()
//Benchmarks.permutationsAndCombinations()
Benchmarks.multiplicationBalanced()
Benchmarks.multiplicationUnbalanced()
//public struct PixelData {
// var a:UInt8 = 255
// var r:UInt8
// var g:UInt8
// var b:UInt8
//}
//
//private let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
//private let bitmapInfo:CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue)
//
//public func imageFromARGB32Bitmap(pixels:[PixelData], width: Int, height: Int) -> CGImage {
// let bitsPerComponent: Int = 8
// let bitsPerPixel: Int = 32
//
// assert(pixels.count == Int(width * height))
//
// var data = pixels // Copy to mutable []
// let providerRef = CGDataProvider(
// data: NSData(bytes: &data, length: data.count * MemoryLayout<PixelData>.size)
// )
//
// let cgim = CGImage(
// width: width,
// height: height,
// bitsPerComponent: bitsPerComponent,
// bitsPerPixel: bitsPerPixel,
// bytesPerRow: width * MemoryLayout<PixelData>.size,
// space: rgbColorSpace,
// bitmapInfo: bitmapInfo,
// provider: providerRef!,
// decode: nil,
// shouldInterpolate: true,
// intent: CGColorRenderingIntent.defaultIntent
// )
// return cgim!
//}
//
//
//@discardableResult
//func writeCGImage(_ image: CGImage, to destinationURL: URL) -> Bool {
// guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypePNG, 1, nil) else {
// print("ERR")
// return false
//
// }
// CGImageDestinationAddImage(destination, image, nil)
// return CGImageDestinationFinalize(destination)
//}
//
//func makeAndSave()
//{
// let dimension = 4000
//
//
// var pixels = [PixelData]()
//
// for i in 1...(dimension * dimension)
// {
// if math.isPrime(i)
// {
// pixels.append(PixelData(a: 255, r: 0, g: 0, b: 0))
// }
// else
// {
// pixels.append(PixelData(a: 0, r: 255, g: 255, b: 255))
// }
// }
//
//
// let img = imageFromARGB32Bitmap(pixels: pixels, width: dimension, height: dimension)
//
// let writeURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!.appendingPathComponent("name.png")
//
// writeCGImage(img, to: writeURL)
//}
//
//benchmarkAndPrint(title: "")
//{
// makeAndSave()
//}