I played with the corrected Mandelbrot code and have two small mods that will decrease execution time by more than 4X.
(1) Data types need to be specified for each variable. The line...
Dim i, j As Double
will define i as a Variant data type and j as a Double. Variants are more expensive than Doubles. This line and all lines like it should be in the form...
Dim i As Double, j As Double
(2) Using DoEvents is expensive and updating the screen is very expensive in Excel. I modified the code to turn off the screen updating and inform the user of progress every 1% using the status bar.
Sub Grid()
With Range(Cells(1, 1), Cells(1900, 1900))
.ColumnWidth = 0.08
.RowHeight = 0.75
End With
End Sub
'----------------------------------------------------
Function iterateQueen(ByVal i As Double, j As Double)
Dim ien As Double, jen As Double, ienz As Double, jenz As Double
Dim xmag As Double, ymag As Double
Dim patri As Integer
xmag = i * i
ymag = j * j
ien = i
jen = j
patri = 1
For k = 1 To 1000
jen = 2 * ien * jen + j
ien = xmag - ymag + i
xmag = ien * ien
ymag = jen * jen
If xmag + ymag > 4 Then
patri = 0
Exit For
End If
Next k
iterateQueen = patri
End Function
'----------------------------------------------------
Sub drawMandelbrot()
Dim pocitadloi As Integer, pocitadloj As Integer
Dim i As Double, j As Double
Dim oldStatusBar As Boolean, k As Integer, numRows As Integer
'Dim timerStart As Single
' Initial application controls
'timerStart = Timer
With Application
.ScreenUpdating = False
oldStatusBar = .DisplayStatusBar
.DisplayStatusBar = True
.StatusBar = "Starting..."
End With
' pro mandelbrotovu mnozinu i od -1 do 1, j od -2 do 1
numRows = Int((2 - (-2)) / 0.003) + 1
For i = -2 To 2 Step 0.003
k = k + 1
pocitadloi = pocitadloi + 1
pocitadloj = 0
For j = -1 To 1 Step 0.003
pocitadloj = pocitadloj + 1
If iterateQueen(i, j) = 1 Then Cells(pocitadloi, pocitadloj).Interior.ColorIndex = 3
Next j
If k Mod Int(numRows / 100) = 0 Then
DoEvents 'prevents status bar from freezing during execution
Application.StatusBar = "Calculating/Outputting... " & Round((k / numRows) * 100, 0) & "%"
End If
Next i
' Ending application controls
With Application
.StatusBar = False
.DisplayStatusBar = oldStatusBar
.ScreenUpdating = True
End With
'MsgBox Round(Timer - timerStart, 2) & " seconds"
End Sub