Intel HD 520 has 24 Execution Units at 1050 MHz to give 403.2 GFLOPS of theoretical FP16 compute performance, 900 MPixel/second pixel rate and 7.20 GPixel/second texture rate.(specifications from Intel Skylake- Intel HD Graphics 500 series).
NVidia Geforce GT 940M has 384 Shading Units(SU), 24 Texture Mapping Units(TMU), 8 Render Output Processors(ROPs) at 1176 MHz, giving 8.58 GPixel/second pixel rate, 25.73 GTexel/second texture rate. It also has a theoretical FP16 performance of 823.3 GFLOPS. (Nvidia CUDA- 900 series Kepler GPU specifications)
Since gaming relies on pixel shading and texture mapping, as well as floating point performance, the Geforce GT 940M is superior to the HD 520 as:
1. GT 940M is 2x faster than HD 520 in Floating Point Calculations,
823.3 GFlops vs 403.2 GFlops
2. GT 940M crushes HD 520 by nearly 10x in Pixel Rate.
8580 MPixels vs 900 MPixels
3. GT 940M destroys HD 520 by a factor of 3x in Texture Rate.
25.73 GTexels vs 7.20 GTexels
(had to use these words to show how much difference there is. Only in extreme situations these words should be used)
This shows that for Graphics (and gaming) the Nvidia GT 940M is better than the Intel HD 520, despite an older processor since 6th Gen and 4th Gen Intel CPUs only have a 10-20% IPC increase in 2 years.
Go for 4th Gen i5, its worth it.