DOUBLE your Google Colab RAM in 10 seconds using these 10 characters

栏目: IT技术 · 发布时间: 4年前

DOUBLE your Google Colab RAM in 10 seconds using these 10 characters

There is one catch: after the 25 GB upgrade, your current runtime’s state will be lost, including local files. You need to run your program again, from scratch. Perhaps upload files again, etc. So if you KNOW that you’ll certainly NEED that extra RAM, allocate it first, before finding out about it after it is too late.

So how do you allocate so much RAM? I found a few solutions online, but (1) they take around 60 seconds (2) they require multiple lines of code.

I decided to come up with an easier solution: a single, 10-character line of code that will do the trick, and do it very fast, in just 10 seconds. Here it is:

[1]*10**10

That’s it. That’s the code. How does it work? Python will attempt to create a list comprised of 10¹⁰=10,000,000,000 integers. However, such a list requires more than 12 GB. In fact, it takes about 80 GB of RAM to store this list. Hence, the session will crash and the upgrade will quickly be available. So: if you are sure that your program will need the double RAM, run [1]*10**10 in a scratch cell (Ctrl/⌘+Alt+N), accept the RAM upgrade, and that’s it. You’re done.

Hope you enjoyed the post! And now, to the coding challenge

And now for the CODING CHALLENGE!

Can you find a shorter piece of code that will use up all the RAM in 10 seconds? Post it in the comments!


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

UNIX网络编程 卷1:套接字联网API(第3版)

UNIX网络编程 卷1:套接字联网API(第3版)

[美]W. 理查德•史蒂文斯(W. Richard Stevens)、比尔• 芬纳(Bill Fenner)、安德鲁 M. 鲁道夫(Andrew M. Rudoff) / 匿名 / 人民邮电出版社 / 2014-6-1 / 129.00

《UNIX环境高级编程(第3版)》是被誉为UNIX编程“圣经”的Advanced Programming in the UNIX Environment一书的第3版。在本书第2版出版后的8年中,UNIX行业发生了巨大的变化,特别是影响UNIX编程接口的有关标准变化很大。本书在保持前一版风格的基础上,根据最新的标准对内容进行了修订和增补,反映了最新的技术发展。书中除了介绍UNIX文件和目录、标准I/......一起来看看 《UNIX网络编程 卷1:套接字联网API(第3版)》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换