我意识到我可能正在推动像AHK这样的脚本语言的限制,但我认为应该可以相对快速地将一些具有1650万条目的数据结构导入到一个对象中。我的意思是我尝试导入的JSON文件只有250MB,游戏加载文件的速度非常快吗?
我尝试使用AHK JSON library导入这个250MB的JSON文件,并且 15分钟。我意识到JSON可能不是为大数据加载而设计的,但是如何更快地导入数据?
我对任何格式或方法持开放态度。
这是我目前的代码,其中一些是注释掉的,这是用于生成和导出对象的代码:
#MaxMem 512
FileDelete, Log.txt
getTimestamp()
{
DllCall("QueryPerformanceCounter", "Int64*", timestamp)
DllCall("QueryPerformanceFrequency", "Int64*", frequency)
return Round(timestamp * 1000 / frequency)
}
splitRGBColor(RGBColor, ByRef red, ByRef green, ByRef blue)
{
red := RGBColor >> 16 & 0xFF
green := RGBColor >> 8 & 0xFF
blue := RGBColor & 0xFF
}
joinRGBColor(red, green, blue)
{
SetFormat Integer, H
red += 0
green += 0
blue += 0
SetFormat Integer, D
StringTrimLeft, red, red, 2
StringTrimLeft, green, green, 2
StringTrimLeft, blue, blue, 2
redLength := StrLen(red)
greenlength := StrLen(green)
blueLength := StrLen(blue)
if (redLength < 2) {
red = 0%red%
}
if (greenLength < 2) {
green = 0%green%
}
if (blueLength < 2) {
blue = 0%blue%
}
hex := "0xff" . red . green . blue
return hex
}
roundHexColor(color1ARGB, colorChunkSize){
;FileAppend, % "Hex: " . color1ARGB . "`n", Log.txt
splitRGBColor(color1ARGB, red, green, blue)
;FileAppend, % "Red: " . red . " Green: " . green . " Blue: " . blue . "`n", Log.txt
red := Round(red / colorChunkSize) * colorChunkSize
green := Round(green / colorChunkSize) * colorChunkSize
blue := Round(blue / colorChunkSize) * colorChunkSize
color1ARGB := joinRGBColor(red, green, blue)
;FileAppend, % "Rounded hex: " . color1ARGB . "`n", Log.txt
return color1ARGB
}
;condensedColors := {}
;loop, 255
;{
; r := A_index
; loop, 255
; {
; g := A_index
; loop, 255
; {
; b := A_index
; rgbHexRaw := joinRGBColor(r, g, b)
; rgbHexRouded := roundHexColor(rgbHexRaw, 5)
; condensedColors[rgbHexRaw] := rgbHexRounded
; }
; }
;}
;colorsJSON := JSON.Dump(condensedColors)
;FileDelete, condensedColors.json
;FileAppend, % colorsJSON, condensedColors.json
FileRead, condensedColorsJSON, condensedColors.json
condensedColors := JSON.Load(condensedColorsJSON)
testColor := 0xff3f975c
FileAppend, % "Test: " . testColor . " is rounded to " . condensedColors[testColor] . ".`n", Log.txt
runCounter := 160000
start := getTimestamp()
loop, %runCounter%
{
roundedColor := condensedColors[0xff3f975c]
}
end := getTimestamp()
duration := end - start
average := duration / runCounter
FileAppend, % "We rounded " . runCounter . " colors in " . duration . "ms, or " . average . "ms per rounded color value.`n", Log.txt
答案 0 :(得分:0)
您将不得不预先解析文件或将其剪切成块并在线程中处理。
您可以使用自定义软件来完成此操作。 Java使线程和解析JSON变得容易。如果你想让它实际上快速写在C。
如果您想要一个基于纯浏览器的解决方案,则必须滚动一个新数据库并预处理插入。