which is calculated in no time
This is not correct. It does take time for Photoshop to calculate. Try saving larger images for web to see it.
You are seeing Photoshop ‘resave’ the file each time you make a change in the color count in ‘save for web’.
If you were to replicate this, you would need some automated function to save a file several times at various index color counts to find the ideal file size. I could not begin to imagine how to do this in Photoshop.
You might want to check out if this is possible in ImageMagick, which loves command line functions and scripting.
but since I’m doing all this for mobile I won’t do any large images
I was only suggesting the use of large images to demonstrate that Photoshop does actually save temp files to calculate file sizes. I don’t think you can get around this without having a function that saves several copies of the same file to find the smallest size.
The long and the short of it is, you can’t do what you’re asking – not natively in photoshop.