What is the bottleneck in this iphone code?

I’m trying to grab screenshots using the script below on the iphone. Application.captureScreenshot works faster than this code on the iphone but then I can’t control the capture area. Both are really slow on the iphone 4s like 1.5 frames per second. I’m wondering if there is any way to speed this up using any new features in the pro version?

import System;
import System.IO;

function UploadPNG () {
        // Create a texture the size of the screen, RGB24 format
        var width = Screen.width;
        var height = Screen.height;
        var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
        // Read screen contents into the texture
        tex.ReadPixels (Rect(0, 0, width, height), 0, 0);
    
        // Encode texture into PNG
        var bytes = tex.EncodeToPNG();
        Destroy (tex);
    
       File.WriteAllBytes(Application.dataPath+"Documents/screenpng"+screencounter+".png", bytes);
        }
    }

What is the bottleneck in this iphone code?

Profile the code. It’s good exercise and will answer your question.

Split the file saving out into a thread. This code will still be slow, but at least you won’t be stalling the update loop while writing to disk.

tex.ReadPixels and File.WriteAllBytes
unfortunately there is no way to really speed up capturing. Especially on iPhone.