L
L
Lici2015-02-22 23:45:31
Objective-C
Lici, 2015-02-22 23:45:31

Why is an OS X application on Swift so slow?

I want to make a text processing soft for myself, so for the test I started writing numbers from 1 to a given number (textCount) in the NSTextView field. So, if you request a miserable 5000 iterations, then the program thinks for 15 seconds. When you specify 10,000 iterations, it generally hangs. And in monitoring the system loads percent by 99%.
It seems that turbo pascal rustled much faster 10 years ago.
Is this some kind of slow development mod, or did I not include something, or why can't the last macbook on a seemingly good Java program count up to 5,000 in 15 seconds? How will he then pick text files of hundreds of megabytes for me?
Code below.

import Cocoa

class ViewController: NSViewController {
    
    @IBOutlet var outcomeText: NSTextView!
    @IBOutlet var textCount: NSTextField!

    @IBAction func TextGenGo(sender: AnyObject) {
        var i:int_least32_t;
        for (i=1;i<=textCount.intValue;i++) {
            outcomeText.string = outcomeText.string! + String(i) + " ";
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}

And it's also not clear why it writes lines not in real time, but thinks and then gives out a complete list.
At the same time, the speed in the console is normal, there are no problems and it writes sequentially, and not all at once at the end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2015-02-23
@Lici

We open the profiler and run it at 5000.
We see that out of the 26 seconds it takes for the program to execute the function, almost all of them go to finish editing the NSTextView.
pikucha.ru/iedeV
Now we do a feint with our ears and display the creation of a line separately, the display for it separately. (I apologize in advance for any errors in the code, this is my first time on Swift)

@IBAction func TextGenGo(sender: AnyObject) {
        var i:int_least32_t;
        var string = outcomeText.string;
        for (i=1;i<=textCount.intValue;i++) {
            string = string! + String(i) + " ";
        }
        outcomeText.string = string;
    }

Now the execution of 20000 took half a second.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question